Skip to content

Commit 9fbf359

Browse files
committed
Rename to hrepeat to tuple
1 parent 1c37a1c commit 9fbf359

File tree

2 files changed

+5
-39
lines changed

2 files changed

+5
-39
lines changed

experiments/idris/src/Fathom/Format/Record.idr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ namespace Format
109109

110110

111111
public export
112-
hrepeat : {len : Nat} -> Vect len Format -> Format
113-
hrepeat fs = MkFormat { Rep, decode, encode } where
112+
tuple : {len : Nat} -> Vect len Format -> Format
113+
tuple fs = MkFormat { Rep, decode, encode } where
114114
Rep : Type
115115
Rep = HVect (map (.Rep) fs)
116116

experiments/idris/src/Playground/HeterogeneousSequences.idr

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,9 @@ import Data.HVect
99
import Fathom.Base
1010
import Fathom.Data.Sing
1111
import Fathom.Format.Record
12-
-- import Fathom.Format.InductiveRecursiveCustom
1312

1413

15-
namespace Format.Pairs
16-
17-
||| Construct a format based on a type tag
18-
value : Nat -> Format
19-
value 1 = u8
20-
value 2 = u16Be
21-
value 4 = u32Be
22-
value _ = fail
23-
24-
25-
||| A heterogeneous sequence of values where the element formats depend on a
26-
||| sequence of type tags
27-
values : (ts : Vect len Nat) -> Format
28-
values [] = pure ()
29-
values (t :: ts) = pair (value t) (values ts)
30-
31-
32-
||| An annoying example from: https://github.com/yeslogic/fathom/issues/394
33-
ouch : Format
34-
ouch = do
35-
len <- u16Be
36-
types <- repeat len u16Be
37-
values <- values types
38-
pure ()
39-
40-
41-
||| Access an element at index @i of the in-memory representation of @values.
42-
||| The type of the returned element is dependent on the sequence of type tags.
43-
index : {ts : Vect len Nat} -> (i : Fin len) -> (values ts).Rep -> (value (index i ts)).Rep
44-
index {ts = _ :: _} FZ (x, _) = x
45-
index {ts = _ :: _} (FS i) (_, xs) = Format.index i xs
46-
47-
48-
namespace Format.HRepeat
14+
namespace Format
4915

5016
||| Construct a format based on a type tag
5117
value : Nat -> Format
@@ -60,6 +26,6 @@ namespace Format.HRepeat
6026
ouch = do
6127
len <- u16Be
6228
types <- repeat len u16Be
63-
values <- hrepeat (map value types)
64-
-- ^^^^^^^ heterogeneous repetitions
29+
values <- tuple (map value types)
30+
-- ^^^^^ heterogeneous sequence of formats
6531
pure ()

0 commit comments

Comments
 (0)