[Haskell-cafe] clonetype
Oleg Grenrus
oleg.grenrus at iki.fi
Mon Sep 24 12:47:29 UTC 2018
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).
So use either tagged-trick/pattern or GND.
Haskell's heavy type machinery exists so we can explicitly and exactly say what we need or want. Tagged/phantom-pattern and GND are different, they have different pros & cons. Having `clonetype-fits-all` seems non-trivial to me.
Sent from my iPhone
> On 24 Sep 2018, at 15.25, Harendra Kumar <harendra.kumar at gmail.com> wrote:
>
> That comes close, but Haskell having such a heavy type machinery to do all the esoteric type stuff in the world, but not allowing you to express such a simple day to day programming thing in a simpler manner is not very satisfying.
>
> -harendra
>
>> On Mon, 24 Sep 2018 at 16:16, Oleg Grenrus <oleg.grenrus at iki.fi> wrote:
>> data MyStringTag
>> type MyString = Tagged MyStringTag String
>>
>> Sent from my iPhone
>>
>>> On 24 Sep 2018, at 13.42, Harendra Kumar <harendra.kumar at gmail.com> wrote:
>>>
>>> Often, we need to create a newtype that is equivalent to a given type for safety reasons. Using type synonym is useless from type safety perspective. With newtype, we have to add a "deriving" clause to it for deriving the required instances, to make it practically useful.
>>>
>>> Does it make sense, and is it possible to have something like a "clonetype" that creates a new type and derives all the instances of the parent type as well? It will be quite helpful in creating equivalent newtype synonyms quickly. Almost always, I do not use a newtype where I should just because of the inconvenience of deriving the instances. Ideally, we should just be able to say something like:
>>>
>>> clonetype MyString = String
>>>
>>> and we are good to go. What is the shortest possible way to achieve this with currently available mechanisms, if any?
>>>
>>> -harendra
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> To (un)subscribe, modify options or view archives go to:
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180924/104fcf1b/attachment.html>
More information about the Haskell-Cafe
mailing list