[Haskell-cafe] [Haskell] A riddle...

Vo Minh Thu noteed at gmail.com
Mon Jul 16 17:36:58 CEST 2012


Oh the mailing list was haskell@ instead of café. Sorry. (Now cc'ing café.)

Andreas, please post this kind of mail to the haskell-cafe instead of
the haskell mailing list.

2012/7/16 Vo Minh Thu <noteed at gmail.com>:
> It seems like the infered type (and thus bounds) is different when you
> force the result to be a Color or not. Just give explicit type
> signatures and conversion functions.
>
> Cheers,
> Thu
>
> 2012/7/16 Andreas Abel <andreas.abel at ifi.lmu.de>:
>> Today a student came to me with a piece of code that worked it executed by
>> itself, but produced different result in the context of his larger problem.
>> We cut down the example to the following:
>>
>>> import Graphics.UI.Gtk
>>>
>>> -- should produce [(26471,0,65535),...
>>> rgbliste =
>>>  (map (\ i ->
>>>   let rb = 5 * (mod (mod 181935629 (4534+i)) 100)-250+128 in
>>>   let gb = 5 * (mod (mod 128872693 (5148+i)) 100)-250+128 in
>>>   let bb = 5 * (mod (mod 140302469 (7578+i)) 100)-250+128 in
>>>   let r = min 255 $ max 0 rb in
>>>   let g = min 255 $ max 0 gb in
>>>   let b = min 255 $ max 0 bb in
>>>   (r*257,g*257,b*257)) [0..])
>>>
>>> --farbliste = map (\ (r,g,b) -> Color r g b) rgbliste
>>>
>>> main :: IO ()
>>> main = do
>>>   print $ head rgbliste
>>
>>
>> If you run it, it prints (26471,0,65535).
>> If you uncomment the def. of farbliste, it prints (44461,65535,65535).
>>
>> I was surprised.  What is going on?
>>
>> Cheers,
>> Andreas
>>
>> --
>> Andreas Abel  <><      Du bist der geliebte Mensch.
>>
>> Theoretical Computer Science, University of Munich
>> Oettingenstr. 67, D-80538 Munich, GERMANY
>>
>> andreas.abel at ifi.lmu.de
>> http://www2.tcs.ifi.lmu.de/~abel/
>>
>>
>> _______________________________________________
>> Haskell mailing list
>> Haskell at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell



More information about the Haskell-Cafe mailing list