Some simple things to help me with my homework and to play around with Haskell.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 

23 lines
696 B

{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies #-}
module Coalgebra where
import Control.Monad.Instances
-- Definitions for (co)algebras, adding fundeps helped in the Automata case...
class Functor f => Algebra f m | m -> f where
phi :: f m -> m
class Functor f => Coalgebra f m | m -> f 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