
In Haskell, I sometimes have to annotate code with type info because the type-inferer otherwise fails (even with |-XNoMonomorphismRestriction)|. Surely, most of the time this is because I was writing buggy code, but sometimes, type annotation just seems needed to get a successful compilation (luckily not as often as in C# 3.0) It seems some new papers appeared regarding this, e.g. http://research.microsoft.com/~simonpj/papers/boxy Is this work being incorporated into GHC? Unfortunately I'm not able to read those papers, so I'm not really sure what it means anyway and what implications (example code?) it would have ;-) Cheers, Peter

2008/5/18 Peter Verswyvelen
In Haskell, I sometimes have to annotate code with type info because the type-inferer otherwise fails (even with -XNoMonomorphismRestriction). Surely, most of the time this is because I was writing buggy code, but sometimes, type annotation just seems needed to get a successful compilation (luckily not as often as in C# 3.0)
Then you must either be programming using extensions or you have found a bug. Haskell 98 should never require annotations (modulo monomorphism). In particular with either higher rank polymorphism or GADTs, full inference is undecidable, so it is perfectly reasonable to have to put a few annotations here and there.
It seems some new papers appeared regarding this, e.g. http://research.microsoft.com/~simonpj/papers/boxy
Is this work being incorporated into GHC?
IIRC that work is already in 6.8. I can't be sure though.
Unfortunately I'm not able to read those papers, so I'm not really sure what it means anyway and what implications (example code?) it would have ;-)
There are some type inference algorithms (Colored Local Type Inference of Scala comes to mind) which can infer quite a lot, but it is pretty difficult to tell when it won't be able to. The main contribution of the FPH is an algorithm which is predictable in that respect. From the paper: "FPH ... has the following delightfully simple rule for when a type annotation is required: a type annotation may be required only for a let-binding or lambda-abstraction that has a non-Damas-Milner type" Here the paper is only referring to higher-rank polymorphism, so its interaction with other extensions can still be tricky. Essentially non-Damas-Milner types are the ones that you wouldn't be able to write down in Haskell without the 'forall' keyword; the ones whose quantification is somewhere besides the top level. Do you have an example of code that required an annotation to compile? Luke

On Sun, 2008-05-18 at 16:57 +0000, Luke Palmer wrote:
2008/5/18 Peter Verswyvelen
: In Haskell, I sometimes have to annotate code with type info because the type-inferer otherwise fails (even with -XNoMonomorphismRestriction). Surely, most of the time this is because I was writing buggy code, but sometimes, type annotation just seems needed to get a successful compilation (luckily not as often as in C# 3.0)
Then you must either be programming using extensions or you have found a bug. Haskell 98 should never require annotations (modulo monomorphism).
This is incorrect. There are two (other) situations where you need type annotations in Haskell 98. One situation is when you use polymorphic recursion, but that is pretty rare unless you are writing nested data types. The other situation is when not enough information is provided to resolve a typeclass constraint, e.g. good ole show . read.

Hello Derek, Sunday, May 18, 2008, 9:10:38 PM, you wrote:
This is incorrect. There are two (other) situations where you need type annotations in Haskell 98. One situation is when you use polymorphic recursion, but that is pretty rare unless you are writing nested data types
can you give examples? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Sun, 2008-05-18 at 21:16 +0400, Bulat Ziganshin wrote:
Hello Derek,
Sunday, May 18, 2008, 9:10:38 PM, you wrote:
This is incorrect. There are two (other) situations where you need type annotations in Haskell 98. One situation is when you use polymorphic recursion, but that is pretty rare unless you are writing nested data types
can you give examples?
-- untested -- all type annotations are necessary -- A nested data type example data PerfectTree a = Leaf a | Succ (PerfectTree (a,a)) size :: PerfectTree a -> Int size (Leaf _) = 1 size (Succ t) = 2 * size t -- a toy example without nested data types f :: Show a => Int -> a -> String f 0 x = show x f n x = f (n-1) (x,x) -- a less toy example bitReverse :: [a] -> [a] bitReverse [x] = [x] bitReverse xs = uncurry (++) . unzip . bitReverse . pairUp $ xs where pairUp [] = [] pairUp (x:y:xs) = (x,y):pairUp xs
participants (5)
-
Andrew Coppin
-
Bulat Ziganshin
-
Derek Elkins
-
Luke Palmer
-
Peter Verswyvelen