Last active
October 26, 2016 03:00
-
-
Save smurphy8/a69135116153113c749ac9a0ccf5d4a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| data Foo = Foo { firstItem :: Int | |
| , secondItem :: Float} | |
| processFoos incomingFoos = do | |
| let foos = fmap firstItem incomingFoost | |
| return $ toJSON $ foos | |
| -- without specification the inferred signature looks like | |
| processFoos :: (Functor f) => f a -> IO () | |
| -- But there are a lot of Functors out there. | |
| -- one might serialize as a list as "[1,2,3,4,5]" | |
| -- but a tree as "{'leaf':[{'leaf':3},{'leaf':4}]}" | |
| runProcessFoos :: IO () | |
| runProcessFoos do | |
| foosFromDB <- getFoosFromDB | |
| processFoos foosFromDB | |
| -- So the DB foos can be changed from a Tree to a list w/o | |
| -- any warning from the compiler | |
| -- however, if the type signature is specified, then the warning | |
| -- comes in nice and clear! | |
| processFoos :: [Foo] -> IO () | |
| -- Now that code can't be changed w/o a warning from the compiler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment