1
Fork 0
This repository has been archived on 2025-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
coalgebra-homework/Coalgebra.hs
2012-10-27 15:34:14 +02:00

23 lines
597 B
Haskell

{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
module Coalgebra where
import Control.Monad
-- Definitions for (co)algebras
class Functor f => Algebra f m where
phi :: f m -> m
class Functor f => Coalgebra f m where
psi :: m -> f m
-- Fixpoint, ie f (Mu f) = Mu f
-- unfortunatly we need a data constructor
data Mu f = In (f (Mu f))
-- The fixpoint is both a algebra and coalgebra,
-- because there is an arrow id: X -> X = FX, if X is a fixpoint
instance Functor f => Algebra f (Mu f) where
phi = In
instance Functor f => Coalgebra f (Mu f) where
psi (In x) = x