Created
August 9, 2011 02:58
-
-
Save akiradeveloper/1133308 to your computer and use it in GitHub Desktop.
While Functor prototype failure
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
newtype While a = While { get :: (a, Bool) } | |
instance Functor While where | |
fmap f (While (a, True)) = let (a', b) = f a in While (a', b) | |
fmap _ (While (a, False)) = While (a, False) | |
countDown :: Int -> (Int, Bool) | |
countDown i = | |
let i' = i - 1 | |
in | |
if i' < 0 then (i, False) else (i', True) | |
main = do | |
let result = get $ While (1, True) `fmap` countDown `fmap` countDown | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You're right. I didn't notice the
'
after one of thei
:s.You could however write