[Haskell-cafe] Splitting data and function declarations over
ryani.spam at gmail.com
Wed Sep 30 13:07:43 EDT 2009
On Wed, Sep 30, 2009 at 8:54 AM, Peter Verswyvelen <bugfact at gmail.com>wrote:
> I guess this is related to the expression problem.
Actually, this is exactly the expression problem :)
> Suppose I have a datatype
> *data Actor = Ball ... | Paddle ... | Wall ...*
> and a function
> *move (Ball ...) = *
> *move (Paddle ...) = *
> *move (Wall ...) = *
> in Haskell one must put *Actor* and *move* into a single file.
> This is rather cumbersome if you work with multiple people or want to keep
> the files small and readable.
> Surely it is possible to use type classes, existentials, etc to split the
> data type into multiple ones, but that's already advanced stuff in a sense.
Yes, and type classes are the current solution. I think the most elegant
solution right now is provided by Data Types a la Carte; see
> But wouldn't it be possible to allow these to be put into multiple files,
> and let the compiler merge them back into one? A bit like C#'s partial
> in file Ball.hs:
> *partial data Actor = Ball ...*
> *move (Ball ...) =*
> in Paddle.hs
> *partial data Actor = Paddle ...*
> *move (Paddle ...) =*
> The compiler would then merge all partial data types and functions into
> As far as no overlap exists in the pattern matches in move, so that the
> order of the pattern matches does not matter at all, the partial trick
> should be possible no?
Yes, that's true. There's some good reading about this proposal here:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe