2019-05-14 00:36:04 +03:00
|
|
|
type Cofree f a = Cofree a (f (Cofree f a))
|
|
|
|
|
|
|
|
type Functor f = Functor (forall a b. (a ->{} b) -> f a ->{} f b)
|
|
|
|
|
|
|
|
use Functor Functor
|
|
|
|
fmap : Functor f -> (a -> b) -> f a -> f b
|
2020-02-22 02:48:12 +03:00
|
|
|
fmap fn f = match fn with
|
2019-05-14 00:36:04 +03:00
|
|
|
Functor map -> map f
|
|
|
|
|
|
|
|
use Cofree Cofree
|
|
|
|
|
|
|
|
namespace Cofree where
|
|
|
|
|
|
|
|
extract : Cofree f a -> a
|
2020-02-22 02:48:12 +03:00
|
|
|
extract = cases
|
2019-05-14 00:36:04 +03:00
|
|
|
Cofree a _ -> a
|
|
|
|
|
|
|
|
duplicate : Functor f -> Cofree f a -> Cofree f (Cofree f a)
|
2020-02-22 02:48:12 +03:00
|
|
|
duplicate f c = match c with
|
2019-05-14 00:36:04 +03:00
|
|
|
Cofree a p -> Cofree c (fmap f (duplicate f) p)
|