I'd guess that type-inference is allowing rgbliste to use Integers when farbliste is commented out, but restricting it to 16 Bit types when it is uncommented. I don't have the GTK module installed on this machine, but try adding some type annotations to see if this is the case.
The maxBound of Word16 appears to confirm my suspicion: Prelude GHC.Word> maxBound :: Word16 65535 On Mon, Jul 16, 2012 at 11:36 PM, Vo Minh Thu <[email protected]> wrote: > 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 <[email protected]>: >> 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 <[email protected]>: >>> 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 >>> >>> [email protected] >>> http://www2.tcs.ifi.lmu.de/~abel/ >>> >>> >>> _______________________________________________ >>> Haskell mailing list >>> [email protected] >>> http://www.haskell.org/mailman/listinfo/haskell > > _______________________________________________ > Haskell-Cafe mailing list > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
