There's an extension to GHC: 'Postfix Operators' .
https://downloads.haskell.org/~ghc/8.6.1/docs/html/users_guide/glasgow_exts.html#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
section.

I also took a leaf out of Oleg's book and built a variadic postfix operator
http://okmij.org/ftp/Haskell/polyvariadic.html

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.


AntC
_______________________________________________
Hugs-Users mailing list
Hugs-Users@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/hugs-users

Reply via email to