# Untypeable Haskell 98

### From HaskellWiki

(Difference between revisions)

NeilMitchell (Talk | contribs) |
DonStewart (Talk | contribs) (categorise) |
||

(One intermediate revision by one user not shown) | |||

Line 1: | Line 1: | ||

− | <haskell> |
+ | Here we document code that looks like it should be valid Haskell98, but |

− | module Test where |
+ | isn't typeable without extensions: |

+ | <haskell> |
||

f :: a -> a |
f :: a -> a |
||

f x = g x |
f x = g x |
||

Line 15: | Line 16: | ||

In GHC making the type of f :: forall a . a -> a, and adding -fglasgow-exts will make this code work. No such luck in Hugs. |
In GHC making the type of f :: forall a . a -> a, and adding -fglasgow-exts will make this code work. No such luck in Hugs. |
||

+ | |||

+ | With pattern type annotations, however, the code works in both Hugs and GHC: |
||

+ | |||

+ | <haskell> |
||

+ | f :: a -> a |
||

+ | f (x :: a) = g x |
||

+ | where |
||

+ | g :: a -> a |
||

+ | g y = bind x y |
||

+ | |||

+ | bind :: a -> a -> a |
||

+ | bind a b = a |
||

+ | </haskell> |
||

+ | |||

+ | [[Category:Proposals]] |

## Latest revision as of 13:48, 21 September 2006

Here we document code that looks like it should be valid Haskell98, but isn't typeable without extensions:

f :: a -> a f x = g x where -- g :: a -> a g y = bind x y bind :: a -> a -> a bind a b = a

The above Haskell code is Haskell 98, rank-1 types, but cannot be given a type signature. Try commenting out the type signature for g and everything will go wrong.

In GHC making the type of f :: forall a . a -> a, and adding -fglasgow-exts will make this code work. No such luck in Hugs.

With pattern type annotations, however, the code works in both Hugs and GHC:

f :: a -> a f (x :: a) = g x where g :: a -> a g y = bind x y bind :: a -> a -> a bind a b = a