Difference between revisions of "Untypeable Haskell 98"
Jump to navigation
Jump to search
DonStewart (talk | contribs) (pattern annotatoins help) |
m (Reverted edits by Tomjaguarpaw (talk) to last revision by DonStewart) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 29: | Line 29: | ||
bind a b = a |
bind a b = a |
||
</haskell> |
</haskell> |
||
+ | |||
+ | [[Category:Proposals]] |
Latest revision as of 15:19, 6 February 2021
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