[Haskell-cafe] clonetype

Oleg Grenrus oleg.grenrus at iki.fi
Mon Sep 24 19:42:29 UTC 2018


On 24.09.2018 17:06, Harendra Kumar wrote:
>
>
> On Mon, 24 Sep 2018 at 18:17, Oleg Grenrus <oleg.grenrus at iki.fi
> <mailto:oleg.grenrus at iki.fi>> wrote:
>
>     The problem is that "All instances" is hard to pin point. We have
>     open world assumption, so instances can be added later (in the
>     dependency tree). Should they be cloned too? And even of you
>     restrict to "instances visible at clonetype definition", that's
>     IMHO not a good idea either, as it's implicit and volatile set
>     (editing imports changes may change the set).
>
>
> A clone type says "both the types are exactly the same in all
> semantics except that they cannot be used interchangeably", it is just
> like "type" except that the types are treated as being different. The
> way visible instances change for the original type by editing imports,
> the same way they change for the clone type as well, I do not see a
> problem there. However, the two types may diverge if we define more
> instances for any of them after cloning and that may potentially be a
> source of confusion?

If you want that, then the GeneralizedNewtypeDeriving is the solution.
It's not so convinient, as you have to list the instances you need, but
on the flip side of the coin is the "explicitness" of the deriving
clause. GHC will barf if you forget an import for an instance you want,
or if you have unused import. Often redundancy is your friend. Type
annotations very often aren't necessary, but it's good practice to write
them (e.g. for top-level definitions). So I'd say that not having
`clonetype` is a feature.

>  
>
>     Haskell's heavy type machinery exists so we can explicitly and
>     exactly say what we need or want.
>
>
> Mortal programmers would love to have "conveniently" added to that
> list :-)
>  
> -harendra
>

- Oleg



More information about the Haskell-Cafe mailing list