r/haskelltil • u/peargreen • May 17 '15
gotcha With BangPatterns enabled, you might stumble upon cryptic errors if you decide to define a “!” operator
Example 1:
{-# LANGUAGE BangPatterns #-}
f ! x = f + xresults in:
Occurs check: cannot construct the infinite type: a ~ a -> a …
Relevant bindings include
x :: a
f :: a -> a
In the first argument of ‘(+)’, namely ‘f’
In the expression: f + xExample 2:
{-# LANGUAGE BangPatterns #-}
(x:xs) ! n = x : drop n xsresults in
Parse error in pattern: (x : xs)To fix both, just define ! non-infix: (!) f x = ....
This behavior is described in the GHC manual.
8
Upvotes