
In the Haskell 98 and 2010 reports it states that one may declare something of the form (tyvar1 -> tyvar2) to be an instance of a type class. Is that a function or what is it? Can anyone point me to an example of this? TIA. Best, - Phil -

On 02/20/2014 11:48 PM, Philippe Sismondi wrote:
In the Haskell 98 and 2010 reports it states that one may declare something of the form /(tyvar1 -> tyvar2)/ to be an instance of a type class. Is that a function or what is it? Can anyone point me to an example of this?
It refers to something like (a -> b) which is the type of functions from 'a' to 'b' (tyvar1 and tyvar2 in the report). Here's a not-terribly-useful example of such an instance: instance Show (a -> b) where show f = "some kinda function" main = print foldl A better example could make those functions an instance of Num, so that you could write f + g to represent f(x) + g(x), f * g for f(x) * g(x), and so on.

Oh, cool, thanks. That clears it up.
I mean, I knew of course that "a -> b" means a function from type a to type b. What I was forgetting is that (->) is a type constructor of kind *->*->*, so an instance declaration could consistently treat (a -> b) as a concrete type like any other.
My thinking is still often contaminated with my pre-Haskell intuitions sometimes. I sometimes revert to thinking of data and functions as being from two different universes. I wonder if I'll ever get over that, or of being a perpetual FP noob. Sigh.
Thanks again.
- Phil -
On 2014-02-21, at 12:02 AM, Michael Orlitzky
On 02/20/2014 11:48 PM, Philippe Sismondi wrote:
In the Haskell 98 and 2010 reports it states that one may declare something of the form /(tyvar1 -> tyvar2)/ to be an instance of a type class. Is that a function or what is it? Can anyone point me to an example of this?
It refers to something like (a -> b) which is the type of functions from 'a' to 'b' (tyvar1 and tyvar2 in the report). Here's a not-terribly-useful example of such an instance:
instance Show (a -> b) where show f = "some kinda function"
main = print foldl
A better example could make those functions an instance of Num, so that you could write f + g to represent f(x) + g(x), f * g for f(x) * g(x), and so on.
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (2)
-
Michael Orlitzky
-
Philippe Sismondi