Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Last active March 29, 2018 22:21
Show Gist options
  • Save Lysxia/70bfeb67071fdd23f5d68eef7d3664f8 to your computer and use it in GitHub Desktop.
Save Lysxia/70bfeb67071fdd23f5d68eef7d3664f8 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Functor.Identity
import GHC.Generics
import Generics.OneLiner.Binary
-- gvalidate implementation
class (a ~ f b) => F f a b
instance (a ~ f b) => F f a b
gvalidate :: forall t t' f. (ADT t t', Constraints t t' (F f), Applicative f) => t -> f t'
gvalidate t = gtraverse @(F f) id t
-- HKD
type family HKD f a where
HKD Identity a = a
HKD f a = f a
-- Example
data Person f = Person
{ name :: HKD f String
, age :: HKD f Int
} deriving Generic
deriving instance Show (Person Identity)
john :: Person Maybe
john = Person (Just "John") (Just 43)
main = do
print (gvalidate john :: Maybe (Person Identity))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment