pattern bug?

Mark P Jones mpj@cse.ogi.edu
Sun, 15 Jul 2001 11:27:12 -0700


| Should this compile?
| 
|  f :: (a -> a -> a) -> Int
|  f (+)   = 0
|  f (*)   = 1
|  f (&&)  = 2
|  f (||)  = 3
| 
| Hugs (Version: February 2001) accepts it without complaint.

I believe that Hugs is correct to accept it.  However, it won't
do what some folks might expect ... in particular, it won't match
on the argument and be able to distinguish between the four
different operators that you've shown.  Instead, the arguments
just introduce new local bindings for those symbols as function
parameters.  The whole definition is therefore equivalent to just:

  f  :: (a -> a -> a) -> Int
  f x = 0
  f x = 1
  f x = 2
  f x = 3

and that in turn means just the same as:

  f  :: (a -> a -> a) -> Int
  f x = 0

Hope this helps!

All the best,
Mark