Skip to content

Instantly share code, notes, and snippets.

@eric-corumdigital
Created August 10, 2018 15:07
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 eric-corumdigital/78d20cabdc5a5fa5bebfc95ddaf9b757 to your computer and use it in GitHub Desktop.
Save eric-corumdigital/78d20cabdc5a5fa5bebfc95ddaf9b757 to your computer and use it in GitHub Desktop.
PureScript HList
module Data.HList where
import Data.Semiring ((+))
import Prim.RowList (Cons, Nil, kind RowList)
import Type.Data.RowList (RLProxy)
import Type.Equality (class TypeEquals)
newtype HList (xs :: RowList) = HList forall r
. (forall y ys. TypeEquals (RLProxy xs) (RLProxy (Cons "" y ys)) => y -> HList ys -> r)
-> (TypeEquals (RLProxy xs) (RLProxy Nil) => r)
-> r
--
cons :: forall x xs. x -> HList xs -> HList (Cons "" x xs)
cons x xs = HList (\c n -> c x xs)
infixr 6 cons as :
nil :: HList Nil
nil = HList (\_ n -> n)
length :: forall xs. HList xs -> Int
length = go 0
where
go :: forall ys. Int -> HList ys -> Int
go n (HList f) = f (\_ r -> go (n + 1) r) n
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment