
Ints can't make up the function part of an application, that must have type (a -> b). In the mean time, the reason it didn't accept test id = id id is because it must fix the argument id to only one type. It infers that id must have type (a -> b), from the fact that it appears in the function position, then sees it in the argument position, and infers that a = (a -> b) which obviously causes a problem. To resolve that problem, you need rank-2 polymorphism. Bob On 2 Sep 2009, at 23:24, aditya siram wrote:
Hi all, Recently I wrote a function that takes a unique identifier that I called 'id'. I then tried to apply the 'id' function to it and GHC did not like that. But it should.
For example in 'test' I have told the compiler that the id argument is an Int. So type inference should be able to determine the first 'id' in 'id id' couldn't possibly be an Int, but it complains. So I explicitly told the compiler the type of 'id' in test1 - this didn't work either. The final function 'test3' works as expected. Is there something I am not understand about the way type inference is supposed to work?
test :: Int -> Int test id = id id
test1 :: Int -> Int test1 id = idFunc id where idFunc :: a -> a idFunc = id
test2 :: Int -> Int test2 myid@id = id myid
test3 :: Int -> Int test3 id = Prelude.id id
thanks ... -deech
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners