Should this compile? f :: (a -> a -> a) -> Int f (+) = 0 f (*) = 1 f (&&) = 2 f (||) = 3 Hugs (Version: February 2001) accepts it without complaint. Regards, --HR ------------------------------------------------------------------ Hamilton Richards, PhD Department of Computer Sciences Senior Lecturer Mail Code C0500 512-471-9525 The University of Texas at Austin Taylor Hall 5.138 Austin, Texas 78712-1188 ham@cs.utexas.edu hrichrds@swbell.net ------------------------------------------------------------------
| 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
participants (2)
-
Hamilton Richards -
Mark P Jones