Re: [Haskell] Haskell's type inference considered harmful [Re: A riddle...]

2012-07-16 Thread Christian Höner zu Siederdissen
Hi Andreas, formally, there is only one problem here: you either need to have NoMono on, or give a general type for your function. I tend to give types for everything top-level. This takes care of 1+2. 3 is actually completely ok, as 181935629 === 7693 | 2^16, as the notes for Data.Word states (a

[Haskell] Haskell's type inference considered harmful [Re: A riddle...]

2012-07-16 Thread Andreas Abel
Congratulations to all that solved the riddle so quickly. (First answer in only 8 Minutes!) Now to the point of the exercise: Shocking realizations. 1. Haskell's type inference is NON-COMPOSITIONAL! In the riddle below, I am defining two things f ("rgbliste") and g ("farbliste"). Even t

Re: [Haskell] A riddle...

2012-07-16 Thread Felipe Almeida Lessa
On Mon, Jul 16, 2012 at 12:33 PM, Vo Minh Thu wrote: > 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. Actually, just *always* give explicit type signatures. Cheers, --

Re: [Haskell] A riddle...

2012-07-16 Thread Christian Hoener zu Siederdissen
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:

Re: [Haskell] A riddle...

2012-07-16 Thread Vo Minh Thu
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 : > Today a student came to me with a piece of code that worked it executed by > itself, bu

[Haskell] A riddle...

2012-07-16 Thread Andreas Abel
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