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

Luke Palmer lrpalmer at gmail.com
Wed Jun 9 18:08:34 EDT 2010

On Wed, Jun 9, 2010 at 12:33 PM, Martin Drautzburg
<Martin.Drautzburg at web.de> wrote:
> So far so good. However my "Named" things are all functions and I don't see I
> ever want to map over any of them. But what I'd like to do is use them like
> ordinary functions as in:
> f::Named (Int->Int)
> f x
> Is there a way to do this, other than writing
> apply::Named Int ->Int
> apply n x = (val_of n) x

What's wrong with that?  (Other than the type signature, but I get
what you mean).  The proper type signature is apply :: Named (Int ->
Int) -> Int -> Int.

You don't need the parentheses:

apply n x = val_of n x

Or just:

apply = val_of

I frequently suggest the following to new Haskellers: don't worry so
much about notation.  Sometimes programmers get a picture in their
heads about how the code *should* look, and then they go through all
manner of ugly contortions to make the notation right.

I suggest that you will encounter much less pain if you accept
Haskell's straightforward notation, and focus on the meaning rather
than the syntax of your program.

So, to summarize:  if you have something that isn't a function and you
want to use it like a function, convert it to a function (using
another function :-P).  That's all.  No syntax magic, just say what
you're doing.


More information about the Haskell-Cafe mailing list