Inferring from context declarations
Lennart Augustsson
lennart@mail.augustsson.net
Thu, 22 Feb 2001 09:10:18 -0500
Thomas Johnsson wrote:
> Lennart Augustsson writes:
> > > Simon Peyton Jones' comments about dictionary passing are a red herring,
> > > since they assume a particular form of compiler. Various (MLj, MLton)
> > > ML compilers already inline out all polymorphism.
> > ML is a language where you can do this. In Haskell it is not always
> > possible to eliminate all polymorphism (due to polymorphic recursion).
>
> I'd like to see an example of this!
Sure, here's one where you can't bound the number of dictionaries:
main = interact $ show . f 'a' . read
f :: (Eq a) => a -> Integer -> Bool
f x 0 = x == x
f x n = f [x] (n-1)
If the input is 0 the comparison is of Char,
if the input is 1 the comparison is of [Char],
if the input is 2 the comparison is of [[Char]],
etc.
Incidentally, this has nothing to do with allowing polymorphic recursion
on functions in Haskell. It could be done earlier too, but then it had
to be encoded using a class and instance declaration.
-- Lennart