[Haskell-cafe] Identity operator for types

Juan Miguel Vilar jvilar at uji.es
Fri May 17 10:33:08 UTC 2019

El 17/5/19 a las 11:56, ALeX Kazik escribió:
> Hi Juan,
>> 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
> Alex.
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.

Juan Miguel

Juan Miguel Vilar Torres
Profesor titular de universidad
Departamento de Lenguajes y Sistemas Informáticos
Escuela Superior de Tecnología y Ciencias Experimentales
Universitat Jaume I
Av. de Vicent Sos Baynat s/n
12071 Castelló de la Plana (Spain)
Tel: +34 964 72 8365
Fax: +34 964 72 8435
jvilar at uji.es

More information about the Haskell-Cafe mailing list