[Haskell-cafe] Identity operator for types
Benjamin Franksen
ben.franksen at online.de
Fri May 17 10:45:18 UTC 2019
Am 17.05.19 um 12:33 schrieb Juan Miguel Vilar:
> El 17/5/19 a las 11:56, ALeX Kazik escribió:
>>> Now, the problem is what can I do to have a type that contains a
>>> single Int? Is there a sort of id for types so that I can write
>>
>> Identity is the solution
>>
>> f :: Example Identity Int -> Int
>> f (Example i) = 2 * runIdentity i
>>
> Thank you Alex, but this forces the use of runIdentity. I am aware that
> Identity Int and Int are isomorphic, but my problem is more aesthetic, I
> would like that the f t was t. I want to use it in a library and I don't
> want the users to be aware of details that should be irrelevant.
> Sometimes they will use lists, sometimes simple times, and would like
> that to be as transparent as possible.
https://reasonablypolymorphic.com/blog/higher-kinded-data/ shows how to
do that using closed type families.
Cheers
Ben
More information about the Haskell-Cafe
mailing list