[Hugs-users] Undocumented featurette: Postfix operators
anthony_clayden at clear.net.nz
Sun Sep 30 06:17:59 UTC 2018
There's an extension to GHC: 'Postfix Operators' .
Turns out Hugs can do that too (in Hugs mode).
> (!) :: Num a => a -> a -- note defined as monadic
> (!) 0 = 1 -- lhs of equation must use prefix form
> (!) n = n * ((n - 1) !) -- but rhs can use postfix
So (3 !) returns 6, etc. The parens are needed so that it's parsed as a
I also took a leaf out of Oleg's book and built a variadic postfix operator
That is, (3 ~- 7) is parsed as 'subtract 3 from 7'. (3 ~-) is parsed as
postfix negate 3 aka 'subtract 3 from zero'. It kinda worked, but the terms
need a lot of explicit signatures and/or tricky type casting.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Hugs-Users