[Haskell-beginners] Replace instances of module

Francesco Ariis fa-ml at ariis.it
Mon Jan 8 15:50:45 UTC 2018


On Mon, Jan 08, 2018 at 04:31:53PM +0200, Baa wrote:
> Actually I don;t know - is some better way to solve such problem? I'm
> sure many of us communicate with some RESTfull APIs. Then APIs change.
> And your apps should work with old and new APIs (services), so you
> should clone existing library to support both versions (together, at
> the same time, in one client application!).

A somewhat primitive but doable solution would be: instead of using
instances pass a datatype around. E.g.

    data J a = J { readjs :: a -> MyTpe }
    myfun :: J a -> a -> Int
    -- when before it probably was
    -- myfun :: FromJson a => a -> Int

You could enforce some sanity at type level with phantom types, e.g.:

    data InterfaceA
    data InterfaceB
    data J a b = -- something
                 -- J is to be exported without (..)
    creaIntfA :: J a InterfaceA

> Are backpacks something like ML modules?

Indeed backpack is a way to have an ML-like module system in Haskell.

The question is interesting and a "real life" one. I urge you to post
it on cafe- too, I am sure there will be some more ideas/solutions in
there.



More information about the Beginners mailing list