Teaching

Claus Reinke claus.reinke at talk21.com
Thu Nov 30 20:05:36 EST 2006


defaulting can also be used for non-standard arithmetic in teaching
(not something you want to let loose on students who you don't
want to know about type classes, though, so be careful where you
demonstrate this;-):

    http://www.cs.kent.ac.uk/people/staff/cr3/toolbox/haskell/R.hs

    Main> foldr1 (*) [1..5]
    (1 * (2 * (3 * (4 * 5))))
    Main> foldl (*) 1 [1..5]
    (((((1 * 1) * 2) * 3) * 4) * 5)
    Main> foldr (*) 1 [1..5]
    (1 * (2 * (3 * (4 * (5 * 1)))))
    Main> map (+) [1..4]
    [\x->(1 + x),\x->(2 + x),\x->(3 + x),\x->(4 + x)]
    Main> map (1+) [1..4]
    [(1 + 1),(1 + 2),(1 + 3),(1 + 4)]
    Main> map (1+) [1..4] :: [Int]
    [2,3,4,5]

this was written long ago, with Hugs in mind, where the defaulting
applies to the interactive loop - with GHCi, you'll need to add
-fglasgow-exts, and still don't get the defaulting interactively (?), 
so you'll need to write the type annotations:

    *Main> foldr (-) 0 [1..4] :: R Int
    (1 - (2 - (3 - (4 - 0))))
    *Main> foldl (-) 0 [1..4] :: R Int
    ((((0 - 1) - 2) - 3) - 4)

of course, this would be fine if defaults could be set in the interactive
loop itself, so you don't need defaults here, and one might argue that
having to give type annotations is annoying, but instructive..

personally, I use default very rarely, but that kind of reasoning has 
never been a good argument for excluding a feature that others like.

I would agree, however, that the monomorphism restriction should go
(warning only), so that defaulting cannot change my 1 :: Num a => a
constants from Behaviours to Integers; with DMR gone, there may
be less need for defaulting, but I would also agree that defaulting 
should be generalized so that its current use becomes a special case
of disambiguating overloading for a whole module/program/session, 
without having to specialize the type-signatures everywhere in the code.

and yes, teaching is important, and Haskell is not only about teaching,
so teaching needs need to be addressed like the needs of any other
important Haskell application area: by optional, but widely supported,
domain-specific libraries/packages/flags/syntax/..

Just my (2 :: Num a => a),
Claus



More information about the Haskell-prime mailing list