[Haskell-cafe] EduHaskell
Ruben Astudillo
ruben.astud at gmail.com
Sun Sep 24 04:16:06 UTC 2017
I just have passing commentary on your issues. For the bigger questions at
the end of the mail I don't have good answers sadly, although just by
convenience on question from SO/reddit/web in general I would stay on
GHC/base so they can search their questions.
On 23/09/17 22:02, erwig wrote:
> * Errors resulting from overloading
On GHC 8.2.1 there is a new flag for `:type +d` which uses
type-defaulting for giving non-overloaded versions for functions.
Prelude> :type +d foldr
foldr :: (a -> b -> b) -> b -> [a] -> b
Prelude> :type foldr
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
That help to return some of the convenience from before Foldable was in
the Prelude. There also -XTypeApplications which lets you play with the
signatures
Prelude> :set -XTypeApplications
Prelude> import Data.Monoid
Prelude> import Data.Set
Prelude> :type +v foldMap
foldMap :: Foldable t => forall m a. Monoid m => (a -> m) -> t a -> m
Prelude> :type foldMap @Set
foldMap @Set :: Monoid m => (a -> m) -> Set a -> m
Prelude> :type foldMap @Set @(Sum _)
foldMap @Set @(Sum _) :: Num w => (a -> Sum w) -> Set a -> Sum w
Prelude> :type foldMap @Set @(Sum Int)
foldMap @Set @(Sum Int) :: (a -> Sum Int) -> Set a -> Sum Int
type +v is to see the explicit forall and thus how the TypeApplications
get applied. Lastly there is more help to see what instances are
available in the form of link in the haddock pages of the classes.
> * Errors due to undefined type class instances (specifically, Eq and
Show)
I would teach to define instances for those clases because they are easy
to do. They work on types of kind * thus are very down to earth. I
remember doing this with LYAH. That way they won't see them as magic and
actually understand why the compiler is barfing.
> * Errors in the context of parametric polymorphism
Those are actually hard. Classes of working on kinds * -> * are what
gives haskell the feeling that the class/instances are hard and magical.
Playing with them is the only to get comfortable though.
--
-- Ruben
-- pgp: 4EE9 28F7 932E F4AD
More information about the Haskell-Cafe
mailing list