Showing posts with label typeclasses. Show all posts
Showing posts with label typeclasses. Show all posts

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.

Wednesday, January 14, 2009

Typeclass Blues

Well, I've been having some trouble with the typeclass implementation. I got rid of the long-standing bug where ill-typed rules were generated in E.FromHs, and I've gotten FrontEnd.Class to generate rules for method implementations which appear in instance declarations, but I haven't figured out how to implicitly fall back to the default implementation. The one approach I actually tried was to generate method implementations like:
Lhc.Order./= = Instance@.iLhc.Order./=.default
which would quickly be rewritten to:
Instance@.iLhc.Order./=.Lhc.IO.IOError = Instance@.iLhc.Order./=.default
but unfortunately, the typechecker stated that Instance@.iLhc.Order./=.default was not in the type-checking environment, and I couldn't figure out why :-(.