Thursday, January 22, 2009

Typeclasses are working, now we're missing a bunch of instances...

Well, I finally figured out why the only two test cases that were working were HelloWorld and Kleisli. The compiler had been implicitly generating a lot of hard-wired instances for Int,Word,CInt, and all their numerous cousins -- but it was generating the methods too late (during conversion from HsSyn language to the E intermediate language) for the methods to be properly associated with their classes (which FrontEnd.Class does before typechecking even properly begins). Since none of us much liked the idea of having all this hardwired into the compiler, we decided that rather than try to adjust the machinery to work with the new handling of methods, we'd rather implement the instances in the library. So, that is what we have to do for every type in the following list:
  • Lhc.Prim.Int
  • Lhc.Basics.Integer
  • Data.Int.Int8
  • Data.Int.Int16
  • Data.Int.Int32
  • Data.Int.Int64
  • Data.Int.IntMax
  • Data.Int.IntPtr
  • Data.Word.Word
  • Data.Word.Word8
  • Data.Word.Word16
  • Data.Word.Word32
  • Data.Word.Word64
  • Data.Word.WordMax
  • Data.Word.WordPtr
  • Foreign.C.Types.CChar
  • Foreign.C.Types.CShort
  • Foreign.C.Types.CInt
  • Foreign.C.Types.CUInt
  • Foreign.C.Types.CSize
  • Foreign.C.Types.CWchar
  • Foreign.C.Types.CWint
  • Foreign.C.Types.CTime

So bear with us if this takes a while to iron out. We have managed to get mini-base to build and many of the tests to run now, though getArgs apparantly doesn't compile yet.

2 comments:

  1. Can it handle having instances in different modules?

    ReplyDelete
  2. Sure. But the methods-binding RULES have to go through the typechecker so that they end up being well typed. Previously, they were generated in E.FromHs, so injecting the methods for primitive instances there was no problem. However, it didn't fare as well with more complicated types (it tended to get type arguments in the wrong order), so I put code in FrontEnd.Class to generate the RULES *before* typechecking, so that the typechecker can annotate them with types and E.FromHs can use the same code it uses for user-provided RULES in order to generate well-typed rules.

    ReplyDelete