[Haskell-beginners] Replace instances of module

Baa aquagnu at gmail.com
Mon Jan 8 14:31:53 UTC 2018


Hello, Francesco.

Actually the whole problem is that I have library (consisting of
several modules: types, API calls, JSON instances, etc) to work with
some REST service. Now I have 2 nodes with this service: version 1 and
version 2, so API is little bit changed in version 2 (mostly in JSON
instances, but types seems to be the same, API calls will be the same
too).

So, clients must work with both services: of version 1 and version 2.
And I can create new library, but this will be big copy-paste, because
mostly code (except JSON instances) will be the same. Different will be
returned value in some API calls, maybe - I'm not sure. Nothing else.

So, if I'll create new version of library: how they will live together
with the same names, etc, only different version?! And common
code-base will lead to complex bug-fixing and test modification. If
I'll name new library like "oldlibv2" - problem with bug fixing and
testing is still here.

My idea was to "patch" in some way existing library by import some
modules into new modules and reimplement some instances only. May be
the same with API calls, I'm not sure here.

I know that it's easy in F#, ML and Python, for example. Are backpacks
something like ML modules? I see that they are not supported by stack.
What does it mean? "import" will not work?

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!).

===
Best regards, Paul

> Hello Paul,
> 
> On Mon, Jan 08, 2018 at 03:20:20PM +0200, Pv wrote:
> > Hello, all.
> > 
> > Is it possible to import all types except some of instances and to
> > re-defined hiding instances, so resulting (new) module will be the
> > same types, mostly the same instances, but some of instances will be
> > replaced?  
> 
> Nope, instances are automatically imported! You can create newtypes
> and have them instances of what you need or check the newfangled
> `backpack` [1]!
> 
> [1] https://ghc.haskell.org/trac/ghc/wiki/Backpack
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners



More information about the Beginners mailing list