[Haskell-cafe] Re: dear traversable

wren ng thornton wren at freegeek.org
Sat Jul 31 23:41:02 EDT 2010


Ben wrote:
> 4) ross, i had to ask ghci to even believe your code type-checks!  i
> didn't realize currying worked that way -- i've never thought to pass
> in functions of different arities.  as an experiment, i tried

N.B. intersectionWith id == intersectionWith ($), which might cause it 
to make a bit more sense. ($) is an infix version of 'id' restricted to 
function types. But then, ($) is a weird combinator; e.g., flip($) is 
the T combinator for type lifting.



> Prelude Data.Map> :t intersectionWith 1
> intersectionWith 1
>   :: (Num (a -> b -> c), Ord k) => Map k a -> Map k b -> Map k c
> 
> [...]
> 
> ps actually the first two don't make much sense to me, when i think
> about it.....

In order to allow overloading of literals, discrete numeric literals are 
parsed as if wrapped in fromInteger(_::Integer) and continuous numeric 
literals are parsed as if wrapped in fromRational(_::Rational). Thus,

     Prelude> :t 1
     1 :: (Num t) => t
     Prelude> :t 1.0
     1.0 :: (Fractional t) => t

So, since intersectionWith is expecting an (a->b->c) we figure out that 
"1" must be interpreted as belonging to that type, which means we need a 
Num(a->b->c) instance.

-- 
Live well,
~wren


More information about the Haskell-Cafe mailing list