Created
August 10, 2018 15:07
-
-
Save eric-corumdigital/78d20cabdc5a5fa5bebfc95ddaf9b757 to your computer and use it in GitHub Desktop.
PureScript HList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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