3 ms·
The book introduced the second pattern out of the blue. What is the difference between those two function definitions? What does "=>" mean in this context? a
by Xurinos 16y ago
The book introduced the second pattern out of the blue. What is the difference between those two function definitions? What does "=>" mean in this context? a :: b -> (c d) -> e makes sense to me, but f :: (g h) => i -> j -> k does not.
Here is the page that suddenly introduced that second form: http://book.realworldhaskell.org/read/data-structures.html http://book.realworldhaskell.org/read/data-structures.html
It is entirely possible I missed some context somewhere in there; "namespaces for values vs types" might be my clue. :)
- eru 16y agoIn the example my_fun :: (TypeClass1 a, Typeclass2 b) => a -> b the stuff preceeding the => declares what typeclasses the types you mention later should fall into. A good example is the module Data.Map; this module deals with finite mappings of keys to values. Since those Maps are based on balanced trees, the keys have to be orderable/comparable. So for inserting a key into a map (http://hackage.haskell.org/packages/archive/containers/0.2.0.1/doc/html/Data-Map.html#5 http://hackage.haskell.org/packages/archive/containers/0.2.0...) we get the following type insert :: Ord k => k -> a -> Map k a -> Map k a This just says that the type of keys has to be an instance of the class Ord (http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/Data-Ord.html http://haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0...). I.e. there has to be an instance declaration with the function (<=) :: a -> a -> Bool Does that help? By the way, if you want to find documentation about a function and you know its name or type, you can use Hoogle (http://www.haskell.org/hoogle/ http://www.haskell.org/hoogle/).
- Xurinos 16y agothe stuff preceeding the => declares what typeclasses the types you mention later should fall into. That makes it clear. Thank you!