Skip to content

Instantly share code, notes, and snippets.

@mpickering
Created January 22, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpickering/37b7119561e825ba895ac2b014d178d7 to your computer and use it in GitHub Desktop.
Save mpickering/37b7119561e825ba895ac2b014d178d7 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GADTs #-}
module Test where
data HList xs where
Nil :: HList '[]
(:>) :: a -> HList xs -> HList (a ': xs)
infixr 9 :>
data T1 = T1 Int Char
foo :: Functor f => (Int -> f Int) -> T1 -> f T1
foo f s = let x = case s of { T1 a b -> a :> b :> Nil }
in fmap (\v -> case x of { _ :> vs -> T1 v (case vs of { v2 :> _ -> v2 }) })
(f (case x of {v1 :> _ -> v1}))
data HList2 where
Nil2 :: HList2
(:>>) :: Int -> HList2 -> HList2
infixr 9 :>>
data T2 = T2 Int Int
foo2 :: Functor f => (Int -> f Int) -> T2 -> f T2
foo2 f s = let x = case s of { T2 a b -> a :>> b :>> Nil2 }
in fmap (\v -> case x of { _ :>> vs -> T2 v (case vs of { v2 :>> _ -> v2 }) })
(f (case x of {v1 :>> _ -> v1}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment