File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed
experiments/idris/src/Fathom/Closed Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -164,3 +164,44 @@ toFormatOfEqIso = MkIso
164164 , toFrom = \(Evidence _ _) => Refl
165165 , fromTo = \(Evidence _ (Element (MkFormat _ _) Refl)) => Refl
166166 }
167+
168+
169+ -------------------------
170+ -- FORMAT CONSTRUCTORS --
171+ -------------------------
172+
173+ -- Helpful constructors for building non-indexed format descriptions.
174+ -- This also tests if we can actually meaningfully use the `Format` type.
175+
176+ namespace Format
177+
178+ public export
179+ end : Format
180+ end = MkFormat () End
181+
182+
183+ public export
184+ fail : Format
185+ fail = MkFormat Void Fail
186+
187+
188+ public export
189+ pure : {0 A : Type} -> (x : A) -> Format
190+ pure x = MkFormat (Sing x) (Pure x)
191+
192+
193+ public export
194+ skip : (f : Format) -> (def : f.Rep) -> Format
195+ skip f def = MkFormat Unit (Skip (toFormatOf f) def)
196+
197+
198+ public export
199+ repeat : (len : Nat) -> Format -> Format
200+ repeat len f = MkFormat (Vect len f.Rep) (Repeat len (toFormatOf f))
201+
202+
203+ public export
204+ bind : (f : Format) -> (Rep f -> Format) -> Format
205+ bind f1 f2 =
206+ MkFormat (x : f1.Rep ** (f2 x).Rep)
207+ (Bind (toFormatOf f1) (\x => toFormatOf (f2 x)))
Original file line number Diff line number Diff line change @@ -159,6 +159,47 @@ toFormatOfEqIso = MkIso
159159 }
160160
161161
162+ -------------------------
163+ -- FORMAT CONSTRUCTORS --
164+ -------------------------
165+
166+ -- Helpful constructors for building non-indexed format descriptions.
167+ -- This also tests if we can actually meaningfully use the `Format` type.
168+
169+ namespace Format
170+
171+ public export
172+ end : Format
173+ end = MkFormat () End
174+
175+
176+ public export
177+ fail : Format
178+ fail = MkFormat Void Fail
179+
180+
181+ public export
182+ pure : {0 A : Type} -> (x : A) -> Format
183+ pure x = MkFormat (Sing x) (Pure x)
184+
185+
186+ public export
187+ skip : (f : Format) -> (def : f.Rep) -> Format
188+ skip f def = MkFormat Unit (Skip (toFormatOf f) def)
189+
190+
191+ public export
192+ repeat : (len : Nat) -> Format -> Format
193+ repeat len f = MkFormat (Vect len f.Rep) (Repeat len (toFormatOf f))
194+
195+
196+ public export
197+ bind : (f : Format) -> (Rep f -> Format) -> Format
198+ bind f1 f2 =
199+ MkFormat (x : f1.Rep ** (f2 x).Rep)
200+ (Bind (toFormatOf f1) (\x => toFormatOf (f2 x)))
201+
202+
162203--------------------
163204-- CUSTOM FORMATS --
164205--------------------
You can’t perform that action at this time.
0 commit comments