[Haskell-cafe] Convert a function to a string of operators?
Bas van Dijk
v.dijk.bas at gmail.com
Sat Mar 5 00:09:24 CET 2011
On 4 March 2011 22:10, Job Vranish <job.vranish at gmail.com> wrote:
> Make your own expression type and make it an instance of the Num typeclass.
This is also the approach I took in repr:
http://hackage.haskell.org/package/repr
For example:
$ cabal install repr
$ ghci
> import Text.Repr
> let r = 1.5 + 2 + (3 + (-4) * (5 - pi / sqrt 6)) :: Repr Double
> extract r
17.281195923884734
> show r
"fromRational (3 % 2) + 2 + (3 + negate 4 * (5 - pi / sqrt 6))"
Bas
More information about the Haskell-Cafe
mailing list