Created
May 4, 2016 01:17
-
-
Save hdgarrood/f4ec9852e20d0f28f01f13689797f3c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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