Skip to content

Commit 2a623d9

Browse files
committed
Add examples for Rec
1 parent a952fe2 commit 2a623d9

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Data/Vinyl/Core.hs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,32 @@ import Control.DeepSeq (NFData, rnf)
5757
import Data.Constraint.Forall (Forall)
5858
#endif
5959

60-
-- | A record is parameterized by a universe @u@, an interpretation @f@ and a
61-
-- list of rows @rs@. The labels or indices of the record are given by
62-
-- inhabitants of the kind @u@; the type of values at any label @r :: u@ is
63-
-- given by its interpretation @f r :: *@.
60+
{- |
61+
A record is parameterized by a universe @u@, an interpretation @f@ and a
62+
list of rows @rs@. The labels or indices of the record are given by
63+
inhabitants of the kind @u@; the type of values at any label @r :: u@ is
64+
given by its interpretation @f r :: *@.
65+
66+
>>> :set -XDataKinds
67+
>>> import Data.Vinyl.Functor (Identity(Identity))
68+
>>> testRec = Identity 3 :& Identity "Hi" :& RNil
69+
>>> :t testRec
70+
testRec :: Num r => Rec Identity '[r, [Char]]
71+
>>> testRec :: Rec Identity '[Int, String]
72+
{3, "Hi"}
73+
74+
>>> testRec = Just 3 :& Nothing :& Just "Hi" :& RNil
75+
>>> :t testRec
76+
testRec :: Num r1 => Rec Maybe '[r1, r2, [Char]]
77+
78+
>>> :set -XTypeApplications
79+
>>> import Data.Vinyl.Functor (ElField(Field))
80+
>>> testRec = Field @'("name", String) "Alice" :& Field @'("age", Int) 20 :& RNil
81+
>>> :t testRec
82+
testRec :: Rec ElField '[ '("name", String), '("age", Int)]
83+
>>> testRec
84+
{name :-> "Alice", age :-> 20}
85+
-}
6486
data Rec :: (u -> *) -> [u] -> * where
6587
RNil :: Rec f '[]
6688
(:&) :: !(f r) -> !(Rec f rs) -> Rec f (r ': rs)

0 commit comments

Comments
 (0)