Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
CTRex
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Rows == A row is then simply a list of such label-type pairs: <haskell> newtype Row a = R [LT a] -- constructor not exported </haskell> Notice that the constructor is not exported, so if we ask for the type of <haskell> origin2 = y := 0 .| x := 0 .| empty </haskell> we get: <haskell> origin2 :: Rec ('Records.R '["x" 'Records.:-> Double, "y" 'Records.:-> Double]) </haskell> Here the implementation of Row leaks a bit. The user cannot write down this type, since Records.R is not exported, and neither is :->. Instead the user should not worry about the implementation and write the type in terms of operations (or let the type be inferred), i.e. : <haskell> origin2 :: Rec ("x" ::= Double :| "y" ::= Double :| Empty) </haskell> Operations on rows are implemented using closed type families. The list of label-type pairs in the row are always sorted. Each operation defined on Rows maintains this invariant. We are sure that no operations which violate this invariant can be created by the user, since the constructor is not exported. To keep the list of label-type pairs sorted, we use the built-in closed type family : <haskell> <.=? :: Symbol -> Symbol -> Bool </haskell> Which compares two symbols at compile time and gives a Bool datakind telling us wether the left is <= than the right. For instance, row extension is implemented as follows: <haskell> type family Extend :: Symbol -> * -> Row * -> Row * where Extend l a (R x) = R (Inject (l :-> a) x) type family Inject :: LT * -> [LT *] -> [LT *] where Inject (l :-> t) '[] = (l :-> t ': '[]) Inject (l :-> t) (l' :-> t' ': x) = Ifte (l <=.? l') (l :-> t ': l' :-> t' ': x) (l' :-> t' ': Inject (l :-> t) x) </haskell>
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width