[Haskell-cafe] Re: Why do functions not inherit class when
renamed?
Xiao-Yong Jin
xj2106 at columbia.edu
Thu Mar 19 20:54:43 EDT 2009
Tomáš Janoušek <tomi at nomi.cz> writes:
> Hello,
>
> On Thu, Mar 19, 2009 at 05:49:34PM -0600, Duane Johnson wrote:
>> I'm not sure I understand what is going on here, but it seems to me that
>> the following assignment of "mult = (*)" causes "mult" to lose out on some
>> of the polymorphic behavior of (*). Is that right? If so, why?
>
> This is the monomorphism restriction kicking in.
>
> See http://www.haskell.org/haskellwiki/Monomorphism_restriction.
>
>> Prelude> let (...) = (*)
>> Prelude> :t (...)
>> (...) :: Integer -> Integer -> Integer
>>
>> Prelude> :set -fno-monomorphism-restriction
>> Prelude> let (...) = (*)
>> Prelude> :t (...)
>> (...) :: (Num a) => a -> a -> a
I believe it is a good practice to always write the function
type.
> Prelude> let mult :: Num a => a -> a -> a ; mult = (*)
> Prelude> :i mult
> mult :: (Num a) => a -> a -> a -- Defined at <interactive>:1:35-38
--
c/* __o/*
<\ * (__
*/\ <
More information about the Haskell-Cafe
mailing list