[Haskell-cafe] Identity operator for types

Jack Kelly jack at jackkelly.name
Fri May 17 23:52:27 UTC 2019


Juan Miguel Vilar <jvilar at uji.es> writes:

> El 17/5/19 a las 13:01, Jack Kelly escribió:
>
>> I do not like the sibling thread's suggestion of using closed type
>> families...
>
> I can't see the sibling thread you mentioned. On the other hand, as I
> said it is sort of an aesthetic question, so I think I can live with
> Identity.

Oh. In that case, here is the blog post they discussed, with the
approach that I personally dislike:

https://reasonablypolymorphic.com/blog/higher-kinded-data/

The key part is the HKD type family:

    {-# LANGUAGE TypeFamilies #-}

    -- "Higher-Kinded Data"
    type family HKD f a where
      HKD Identity a = a
      HKD f        a = f a

    data Person' f = Person
      { pName :: HKD f String
      , pAge  :: HKD f Int
      } deriving (Generic)

HTH,

-- Jack


More information about the Haskell-Cafe mailing list