Gelf Mrogen wrote:
>>typeclass Foo 'a 'b where
>>  testFoo: 'a -> 'b -> bool
> 
>>let doFoo: 'b -> bool =
>>  fun b -> testFoo 3 b
> 
> Answer:  No, instance selection should always be done based on the apparent
> types of things, never on the actual types.  In this case, if there
> isn't an instance
> for (testFoo Int a) in scope at the time, it's an error.  If you want
> otherwise, add a
> typeclass constraint to doFoo.

So your solution is: at point of type class instantiation, either an
instance is available, or you must push type class resolution back to
the client. In this case:

let doFoo: 'b -> bool =
  fun b -> testFoo 3 b

becomes

let doFoo: Foo int 'b => 'b -> bool =
  fun b -> testFoo 3 b

if no instance is available to doFoo.

I think that works, because when writing doFoo, either you have a
specific behaviour/instance in mind, or you're making it generic for
clients, in which case they should be providing the specific behaviour.

Sandro

_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to