After reasonable success with an FFI exercise, I have run into a
typing issue that has me stuck.

The foreign software is a C plotting library that my colleagues
use, really simple and mostly quite amenable to Haskell-ization.
The one fly in the ointment is the graph coordinate type, which
is a union of double & int64.  The graph object has switches for
the actual type of x and y coordinates, set at creation time.

So
    plot :: GraphIntInt -> [CLLong] -> [CLLong] -> IO ()
    plot :: GraphIntFloat -> [CLLong] -> [CDouble] -> IO ()
    plot :: GraphFloatInt -> [CDouble] -> [CLLong] -> IO ()
    plot :: GraphFloatFloat -> [CDouble] -> [CDouble] -> IO ()

That wasn't hard to do with a different name for each plot function -
"plotIntInt", "plotIntFloat", etc.,  and this has the desired effect,
that the type enforces the use of the correct coordinate types for the
graph type.

But for a typeclass function "plot" ... is there some way to express
the coordinate types in the graph type?

   class Coords (g x y) where
      plot :: g -> [x] -> [y] -> IO ()
   instance Coords (GraphIntInt CLLong CLLong) where
      ...
   instance Coords (GraphIntFloat CLLong CDouble) where
      ...

Of course this isn't a major problem, it just seemed like I might be
missing something.  Thanks,

        Donn Cave, [EMAIL PROTECTED]

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to