Type class inference trouble

Dylan Thurston dpt@math.harvard.edu
Thu, 15 Feb 2001 21:38:54 -0500


--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Thu, Feb 15, 2001 at 09:08:13PM -0500, Dylan Thurston wrote:
> On Thu, Feb 15, 2001 at 02:37:09PM -0500, Ken Shan wrote:
> >     test2 = apply [int 3] (apply [(+)::Int->Int->Int] [int 5])
> 
> What's strange is that when I tried this just now, the identical line at
> the interpreter prompt returned the correct answer [8].  This is with
> Hugs from February 2000; I'm about to download and try the new version.

The same thing happens with the latest Hugs (February 2001).

I've attached the complete file.  The exact error message is
Reading file "/home/dpt/haskell/progs/test.hs": 
Parsing........................................................................ 
Dependency analysis............................................................ 
Type checking 
ERROR /home/dpt/haskell/progs/test.hs:18 - Unresolved top-level overloading 
*** Binding             : test 
*** Outstanding context : Applicable Int (Int -> Int) b 

Again, commenting out the definition of 'test' and typing the same
thing at the interpreter prompt works fine.

Best,
	Dylan Thurston

--tThc/1wpZn/ma/RB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="test.hs"

import Monad

class Applicable a b c | a b -> c where
  apply :: a -> b -> c

instance Applicable a (a -> b) b where
  apply x f = f x
instance Applicable (a -> b) a b where
  apply f x = f x
instance (Monad m, Applicable a b c) => Applicable (m a) (m b) (m c) where
  apply = liftM2 apply

int :: Int -> Int
int = id
plus :: Int -> Int -> Int
plus = (+)

--test = apply [int 3] (apply [plus] [int 5])



--tThc/1wpZn/ma/RB--