Skip to content

Instantly share code, notes, and snippets.

@nobsun
Last active August 29, 2015 14:02
Show Gist options
  • Save nobsun/4c2413a71a0d6640e75c to your computer and use it in GitHub Desktop.
Save nobsun/4c2413a71a0d6640e75c to your computer and use it in GitHub Desktop.
リストを(非)正格に構成する
data I a = I {unI :: a}
instance Functor I where
fmap f (I a) = I (f a)
instance Monad I where
return = I
I x >>= f = f x
foo :: [I a] -> I [a]
foo [] = return []
foo (ix:ixs) = do { x <- ix; xs <- foo ixs; return (x:xs) }
bar :: [I a] -> I [a]
bar = return . map unI
ss :: [I ()]
ss = repeat (I undefined)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment