[Haskell-cafe] Printing the function result

Brent Yorgey byorgey at gmail.com
Wed Jul 25 14:38:46 EDT 2007


On 7/25/07, Alexteslin <alexteslin at yahoo.co.uk> wrote:
>
>
> Hi,
>
> I am going through examples from the textbook and trying them out but some
> don't work.
> For example:
>
> addNum :: Int -> (Int -> Int)
> addNum n = addN
>         where
>         addN m = n+m
>
> This error message i am getting:
>
> ERROR - Cannot find "show" function for:
> *** Expression : addNum 4
> *** Of type    : Int -> Int


Hi,

Printing functions is in general not possible, since given a function f
there is no way to "get at" its implementation.*  Functions are like black
boxes.  The only way to observe a function is to observe its effect on
various inputs.  So you can try (addNum 4) 6,  (addNum 4) 0, and so on to
see what the function (addNum 4) does to various Int values.

cheers,
-Brent

*(If there were it would lead to all sorts of fun
non-referential-transparency...)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070725/ffbf8e8b/attachment.htm


More information about the Haskell-Cafe mailing list