Skip to content

Instantly share code, notes, and snippets.

@smurphy8
Last active October 26, 2016 03:00
Show Gist options
  • Select an option

  • Save smurphy8/a69135116153113c749ac9a0ccf5d4a7 to your computer and use it in GitHub Desktop.

Select an option

Save smurphy8/a69135116153113c749ac9a0ccf5d4a7 to your computer and use it in GitHub Desktop.
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