[Haskell-cafe] How to "Show" an Operation?

Martin Drautzburg Martin.Drautzburg at web.de
Sun Jun 6 16:50:24 EDT 2010

On Friday, 4. June 2010 18:02:15 Daniel Fischer wrote:
> On Friday 04 June 2010 17:37:16, Martin Drautzburg wrote:
> > Dear all,
> >
> > If I have a problem where I have to select from a set of operations, how
> > would I print the result?
> >
> > Example: If I can chose from (x+y), (x*y), (x^2+y)...
> > and I feed them all into my problem solver
> > and it finds that "(x*y) is right", how can I print that string?
> You'd have to pass the description string to the problem solver too.
> If it was previously
> solver :: Num a => Whatever -> [a -> a -> a] -> Result
> it would become for example
> solver :: Num a => Whatever -> [(a -> a -> a, String)] -> Result

Thanks to Ozgur Akgun for his suggestion. However I really wanted a "human 
readable" name, but admittedly I haven't said so.

About this one:

The only thing I miss in this solution, is that the name is identified by its 
position in the Pair. In this case this is certainly not a problem. But 
anyways, I tried to give it a name, using record syntax. 

This worked well until I wanted to define a different set of operations, which 
should also be named. It turned out that the "name" function, which was 
implicitly created (using record syntax) cannot be used again.

How should I work around that. I could use two different "name" function, but 
I don't like this. Would I have to define a typeclass "namedFunction" which 
all have a "name" function? 

I guess my mind is still a bit stuck in the OO world.


More information about the Haskell-Cafe mailing list