[Haskell-beginners] Question about List Type Constraint and Null

aditya siram aditya.siram at gmail.com
Sat Jan 22 23:29:33 CET 2011


Wow, 'reads' is a weird function. Thanks a bunch for the explanation.
-deech

On Sat, Jan 22, 2011 at 4:26 PM, Daniel Fischer
<daniel.is.fischer at googlemail.com> wrote:
> On Saturday 22 January 2011 23:11:07, aditya siram wrote:
>> > The value of `null res' for a given String obviously depends on the
>> > type at which res is used.
>>
>> Why does it matter what the type of res is as long as it is some kind
>> of list? Doesn't 'reads' always gives [(a1,String)]? So why does it
>> matter what type 'a1' is?
>
> Because
>
> reads "True, that" :: [(Bool,String)]
> ~> [(True,", that")]
>
> and
>
> reads "True, that" :: [(Int,String)]
> ~> []
>
> So to evaluate `null res', the type of res must be known/fixed.
> If it isn't, the compiler has two choices.
> It can refuse to compile or it can compile and let the runtime throw an
> error "Can't evaluate because I don't know the type" (I think the second
> option isn't available for GHC).
> In my opinion, the first option is preferable.
>
>>
>> Thanks for the clear explanation of the monomorphism restriction.
>> -deech
>
>



More information about the Beginners mailing list