[Haskell] A riddle...

Christian Hoener zu Siederdissen choener at tbi.univie.ac.at
Mon Jul 16 17:35:10 CEST 2012


Hi,

well, rgbliste has type:
*Main> :t rgbliste 
rgbliste :: [(Integer, Integer, Integer)]

unless you have farbliste as well, in which case it is:

 *Main> :t rgbliste 
 rgbliste :: [(GHC.Word.Word16, GHC.Word.Word16, GHC.Word.Word16)]

Of course, with NoMonomorphismRestriction, the type becomes:

*Main> :t rgbliste 
rgbliste :: Integral t => [(t, t, t)]

So you restrict rgbliste to Word16's, once you have farbliste.



... I have not checked that the modulo calculations are actually correct
modulo Word16, or modulo Integer...


Gruss,
Christian

* Andreas Abel <andreas.abel at ifi.lmu.de> [16.07.2012 17:28]:
> 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell/attachments/20120716/ca8c2fd6/attachment.pgp>


More information about the Haskell mailing list