
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 Now, the type of show is a->String, but i need some kind of function to print the function as a result. I tried some input output functions but i don't think that is the right way to follow. Can anyone suggest me where to look? Thank you -- View this message in context: http://www.nabble.com/Printing-the-function-result-tf4145303.html#a11790986 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

On 7/25/07, Alexteslin
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...)

Thank you guys, i didn't understand the concept of the chapter. Brent Yorgey wrote:
On 7/25/07, Alexteslin
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...)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/Printing-the-function-result-tf4145303.html#a11798690 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

On Wed, Jul 25, 2007 at 11:27:59AM -0700, Alexteslin 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
Now, the type of show is a->String, but i need some kind of function to print the function as a result. I tried some input output functions but i don't think that is the right way to follow.
Can anyone suggest me where to look?
You can't print function values because there is no reasonable way to do it; printing the definition would break useful equations like 2 + 2 = 4 (since show (\_ -> 2 + 2) == "\_ -> 2 + 2" /= "\_ -> 4" == show (\_ -> 4); printing the table of values would take forever for a big type like Int (at least a billion constructors, many more on some systems), etc. You can print applications of functions, however; (addNum 4) 10 ==> 14 (addNum 4) 20 ==> 24 etc. Stefan
participants (3)
-
Alexteslin
-
Brent Yorgey
-
Stefan O'Rear