3 ms·
In the example my_fun :: (TypeClass1 a, Typeclass2 b) => a -> b the stuff preceeding the => declares what typeclasses the types you mention later should fal
by eru 17y ago
In 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 17y agothe stuff preceeding the => declares what typeclasses the types you mention later should fall into. That makes it clear. Thank you!