I just accidentally discovered a function declaration syntax that I have never seen before
\> add :: Int -> Int -> Int = (+)
\> add 1 2
3
\> -- or with points
\> add' :: Int -> Int -> Int = \x y -> x + y
\> add' 3 4
7
\> -- multi line
\> :{
> add''
> :: Int -> Int -> Int
> = \x y
> -> x + y
> :}
\> add'' 5 6
11
How come i have never seen this anywhere?
It is using the grammar for pattern type signatures.
Furthermore, by the time you write polymorphic functions: This is rejected:
g :: a -> a = \x -> x -- rejected
Generally, pattern bindings may not have type variables. (I don’t know why, but it’s documented.) Pattern bindings mean pattern = expr, and recall that a special case is var = expr such as g = \x -> x.
Correction to your correction: Pattern signatures used to be part of GHC, and Hugs vintage 2006 – as a somewhat loosely documented extension. Then they got taken out of GHC; then put back in GHC2021. I think there’s work in hand to put back result signatures per my add2 above(?) But in a more limited form than was always supported in Hugs.