Skip to content

Instantly share code, notes, and snippets.

@hdgarrood hdgarrood/Main.purs

Created May 4, 2016
Embed
What would you like to do?
module Main where
import Prelude
import Data.Maybe (Maybe)
import Data.List (List)
import Control.Monad.Eff.Console (print)
import Control.Comonad.Cofree (Cofree, mkCofree, head, tail)
import Control.Alternative (class Alternative)
import Control.Plus (empty)
replicate :: forall f a. (Alternative f) => Int -> a -> Cofree f a
replicate 1 a = mkCofree a empty
replicate n a = mkCofree a $ pure (replicate (n-1) a)
class Show1 (f :: * -> *) where
show1 :: forall a. Show a => f a -> String
instance show1array :: Show1 Array where
show1 = show
instance show1maybe :: Show1 Maybe where
show1 = show
instance show1list :: Show1 List where
show1 = show
newtype C f a = C (Cofree f a)
instance showC :: (Show1 f, Show a, Functor f) => Show (C f a) where
show (C cofree) =
"(" <> show (head cofree) <> ") :< (" <> show1 (map C (tail cofree)) <> ")"
x :: forall f. (Alternative f) => C f Char
x = C (replicate 4 'X')
main = do
print "hi"
print (x :: C Array Char)
print (x :: C Maybe Char)
print (x :: C List Char)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.