[Haskell-cafe] Convert a function to a string of operators?
job.vranish at gmail.com
Fri Mar 4 22:10:19 CET 2011
Make your own expression type and make it an instance of the Num typeclass.
Then you can build your expression using the usual operators and then use
show to convert to a string.
It probably does more than you want, but you should be able to get the basic
The really slick thing about it is that you can use expression type on any
function that takes a Num and you'll get a representation of the computation
that took place to get the result.
show (baw a b c :: Int) -- will show you an int
show (baw a b c :: Expr) -- will give you "(a + b) * c" (well... a, b, c
will be replace by whatever you passed in, but you can make them variable
names just the same)
On Fri, Mar 4, 2011 at 3:32 PM, Evgeny Grablyk <evgeny.grablyk at gmail.com>wrote:
> I was wondering if it was possible to "convert" a function (which may
> also call functions) to a plain list of operators on parameters.
> foo a b = a + b
> bar a b = a * b
> baw a b c = bar (foo a b) c
> baw' a b c = (a + b) * c
> Any way to get `baw'' from `baw'? Preferrably as a String.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe