Skip to content

Commit ef54092

Browse files
committed
Begin constructors for wrapper index formats
1 parent 11d58fc commit ef54092

File tree

2 files changed

+110
-22
lines changed

2 files changed

+110
-22
lines changed

experiments/idris/src/Fathom/Closed/InductiveRecursive.idr

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,17 @@ mutual
6161
Rep (Bind f1 f2) = (x : Rep f1 ** Rep (f2 x))
6262

6363

64-
-- Support for do notation
64+
namespace Format
6565

66-
public export
67-
pure : {0 A : Type} -> A -> Format
68-
pure = Pure
66+
-- Support for do notation
6967

70-
public export
71-
(>>=) : (f : Format) -> (Rep f -> Format) -> Format
72-
(>>=) = Bind
68+
public export
69+
pure : {0 A : Type} -> A -> Format
70+
pure = Pure
71+
72+
public export
73+
(>>=) : (f : Format) -> (Rep f -> Format) -> Format
74+
(>>=) = Bind
7375

7476

7577
---------------------------
@@ -169,3 +171,47 @@ toFormatOfEqIso = MkIso
169171
, toFrom = \(Evidence _ (MkFormatOf _)) => Refl
170172
, fromTo = \(Evidence _ (Element _ Refl)) => Refl
171173
}
174+
175+
176+
---------------------------------
177+
-- INDEXED FORMAT CONSTRUCTORS --
178+
---------------------------------
179+
180+
-- Helpful constructors for building index format descriptions.
181+
-- This also tests if we can actually meaningfully use the `FormatOf` type.
182+
183+
namespace FormatOf
184+
185+
public export
186+
end : FormatOf Unit
187+
end = MkFormatOf End
188+
189+
190+
public export
191+
fail : FormatOf Void
192+
fail = MkFormatOf Fail
193+
194+
195+
public export
196+
pure : {0 A : Type} -> (x : A) -> FormatOf (Sing x)
197+
pure x = MkFormatOf (Pure x)
198+
199+
200+
public export
201+
skip : {0 A : Type} -> (f : FormatOf A) -> (def : A) -> FormatOf Unit
202+
skip f def with (toFormatEq f)
203+
skip _ def | (Element f prf) = MkFormatOf (Skip f (rewrite prf in def))
204+
205+
206+
public export
207+
repeat : {0 A : Type} -> (len : Nat) -> FormatOf A -> FormatOf (Vect len A)
208+
repeat len f with (toFormatEq f)
209+
repeat len _ | (Element f prf) =
210+
toFormatOfEq (Element (Repeat len f) (cong (Vect len) prf))
211+
212+
213+
public export
214+
bind : {0 A : Type} -> {0 B : A -> Type} -> (f : FormatOf A) -> ((x : A) -> FormatOf (B x)) -> FormatOf (x : A ** B x)
215+
bind f1 f2 with (toFormatEq f1)
216+
bind _ f2 | (Element f1 prf) =
217+
?todoFormatOf_bind

experiments/idris/src/Fathom/Closed/InductiveRecursiveCustom.idr

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ mutual
6262
Rep (Custom f) = f.Rep
6363

6464

65+
namespace Format
66+
67+
-- Support for do notation
68+
69+
public export
70+
pure : {0 A : Type} -> A -> Format
71+
pure = Pure
72+
73+
public export
74+
(>>=) : (f : Format) -> (Rep f -> Format) -> Format
75+
(>>=) = Bind
76+
77+
6578
---------------------------
6679
-- ENCODER/DECODER PAIRS --
6780
---------------------------
@@ -103,21 +116,6 @@ encode (Bind f1 f2) (x ** y) =
103116
encode (Custom f) x = f.encode x
104117
105118
106-
--------------
107-
-- NOTATION --
108-
--------------
109-
110-
-- Support for do notation
111-
112-
public export
113-
pure : {0 A : Type} -> A -> Format
114-
pure = Pure
115-
116-
public export
117-
(>>=) : (f : Format) -> (Rep f -> Format) -> Format
118-
(>>=) = Bind
119-
120-
121119
--------------------
122120
-- CUSTOM FORMATS --
123121
--------------------
@@ -210,6 +208,50 @@ toFormatOfEqIso = MkIso
210208
}
211209
212210
211+
---------------------------------
212+
-- INDEXED FORMAT CONSTRUCTORS --
213+
---------------------------------
214+
215+
-- Helpful constructors for building index format descriptions.
216+
-- This also tests if we can actually meaningfully use the `FormatOf` type.
217+
218+
namespace FormatOf
219+
220+
public export
221+
end : FormatOf Unit
222+
end = MkFormatOf End
223+
224+
225+
public export
226+
fail : FormatOf Void
227+
fail = MkFormatOf Fail
228+
229+
230+
public export
231+
pure : {0 A : Type} -> (x : A) -> FormatOf (Sing x)
232+
pure x = MkFormatOf (Pure x)
233+
234+
235+
public export
236+
skip : {0 A : Type} -> (f : FormatOf A) -> (def : A) -> FormatOf Unit
237+
skip f def with (toFormatEq f)
238+
skip _ def | (Element f prf) = MkFormatOf (Skip f (rewrite prf in def))
239+
240+
241+
public export
242+
repeat : {0 A : Type} -> (len : Nat) -> FormatOf A -> FormatOf (Vect len A)
243+
repeat len f with (toFormatEq f)
244+
repeat len _ | (Element f prf) =
245+
toFormatOfEq (Element (Repeat len f) (cong (Vect len) prf))
246+
247+
248+
public export
249+
bind : {0 A : Type} -> {0 B : A -> Type} -> (f : FormatOf A) -> ((x : A) -> FormatOf (B x)) -> FormatOf (x : A ** B x)
250+
bind f1 f2 with (toFormatEq f1)
251+
bind _ f2 | (Element f1 prf) =
252+
?todoFormatOf_bind
253+
254+
213255
-----------------
214256
-- EXPERIMENTS --
215257
-----------------

0 commit comments

Comments
 (0)