Skip to content

Commit 6ffd327

Browse files
committed
Try a different FormatOf representation
1 parent 53d50c6 commit 6ffd327

File tree

4 files changed

+21
-46
lines changed

4 files changed

+21
-46
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Fathom.Data.Sing
1818

1919
||| Universe of format descriptions indexed by their machine representations
2020
public export
21-
data FormatOf : (0 Rep : Type) -> Type where
21+
data FormatOf : (0 A : Type) -> Type where
2222
End : FormatOf Unit
2323
Fail : FormatOf Void
2424
Pure : {0 A : Type} -> (x : A) -> FormatOf (Sing x)
@@ -42,8 +42,9 @@ public export
4242
-- ENCODER/DECODER PAIRS --
4343
---------------------------
4444

45+
4546
export
46-
decode : {0 Rep : Type} -> (f : FormatOf Rep) -> Decode (Rep, Colist a) (Colist a)
47+
decode : {0 A, S : Type} -> (f : FormatOf A) -> Decode (A, Colist S) (Colist S)
4748
decode End [] = Just ((), [])
4849
decode End (_::_) = Nothing
4950
decode Fail _ = Nothing
@@ -65,7 +66,7 @@ decode (Bind f1 f2) buffer = do
6566
6667
6768
export
68-
encode : {0 Rep : Type} -> (f : FormatOf Rep) -> Encode Rep (Colist a)
69+
encode : {0 A, S : Type} -> (f : FormatOf A) -> Encode A (Colist S)
6970
encode End () = Just []
7071
encode (Pure x) (MkSing _) = Just []
7172
encode (Skip f def) () = encode f def

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

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import Data.Vect
2727

2828
import Fathom.Base
2929
import Fathom.Data.Sing
30-
import Fathom.Data.Refine
3130

3231
-- import Fathom.Open.Record
3332

@@ -155,35 +154,23 @@ encode (Bind f1 f2) (x ** y) = do
155154

156155
||| A format description refined with a fixed representation
157156
public export
158-
FormatOf : (0 Rep : Type) -> Type
159-
FormatOf rep = Refine Format (\f => Rep f = rep)
160-
161-
162-
toFormatOf : (f : Format) -> FormatOf (Rep f)
163-
toFormatOf f = MkRefine f
157+
data FormatOf : (0 A : Type) -> Type where
158+
MkFormatOf : (f : Format) -> FormatOf (Rep f)
164159

165160

166161
export
167162
either : (cond : Bool) -> (f1 : Format) -> (f2 : Format) -> FormatOf (if cond then Rep f1 else Rep f2)
168-
either True f1 _ = MkRefine f1
169-
either False _ f2 = MkRefine f2
163+
either True f1 _ = MkFormatOf f1
164+
either False _ f2 = MkFormatOf f2
170165

171166

172-
export
167+
public export
173168
orPure : (cond : Bool) -> FormatOf a -> (def : a) -> FormatOf (if cond then a else Sing def)
174169
orPure True f _ = f
175-
orPure False _ def = MkRefine (Pure def)
170+
orPure False _ def = MkFormatOf (Pure def)
176171

177172

178-
export
173+
public export
179174
orPure' : (cond : Bool) -> FormatOf a -> (def : a) -> FormatOf (if cond then a else Sing def)
180175
orPure' True f _ = f
181-
orPure' False _ def = MkRefine (Pure def)
182-
183-
184-
foo : (cond : Bool) -> (f : Format) -> Rep f -> Format
185-
foo cond f def = case orPure cond (toFormatOf f) def of
186-
MkRefine f' {prf} =>
187-
Bind f' (\x => case cond of
188-
True => ?todo1
189-
False => ?todo2)
176+
orPure' False _ def = MkFormatOf (Pure def)

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,38 +135,30 @@ u8 = Custom (MkCustomFormat
135135
136136
||| A format description refined with a fixed representation
137137
public export
138-
FormatOf : (0 Rep : Type) -> Type
139-
FormatOf rep = Refine Format (\f => Rep f = rep)
138+
data FormatOf : (0 Rep : Type) -> Type where
139+
MkFormatOf : (f : Format) -> FormatOf (Rep f)
140140
141141
142142
toFormatOf : (f : Format) -> FormatOf (Rep f)
143-
toFormatOf f = MkRefine f
143+
toFormatOf f = MkFormatOf f
144144
145145
146146
export
147147
either : (cond : Bool) -> (f1 : Format) -> (f2 : Format) -> FormatOf (if cond then Rep f1 else Rep f2)
148-
either True f1 _ = MkRefine f1
149-
either False _ f2 = MkRefine f2
148+
either True f1 _ = MkFormatOf f1
149+
either False _ f2 = MkFormatOf f2
150150
151151
152152
export
153153
orPure : (cond : Bool) -> FormatOf a -> (def : a) -> FormatOf (if cond then a else Sing def)
154154
orPure True f _ = f
155-
orPure False _ def = MkRefine (Pure def)
155+
orPure False _ def = MkFormatOf (Pure def)
156156
157157
158158
export
159159
orPure' : (cond : Bool) -> FormatOf a -> (def : a) -> FormatOf (if cond then a else Sing def)
160160
orPure' True f _ = f
161-
orPure' False _ def = MkRefine (Pure def)
162-
163-
164-
foo : (cond : Bool) -> (f : Format) -> Rep f -> Format
165-
foo cond f def = case orPure cond (toFormatOf f) def of
166-
MkRefine f' {prf} =>
167-
Bind f' (\x => case cond of
168-
True => ?todo1
169-
False => ?todo2)
161+
orPure' False _ def = MkFormatOf (Pure def)
170162

171163

172164
-- Reproduction of difficulties in OpenType format

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Data.Colist
1515
import Data.Vect
1616

1717
import Fathom.Base
18-
import Fathom.Data.Refine
1918
import Fathom.Data.Sing
2019

2120

@@ -147,9 +146,5 @@ public export
147146
148147
||| A format description refined with a fixed representation
149148
public export
150-
FormatOf : (0 Rep : Type) -> Type
151-
FormatOf rep = Refine Format (\f => f.Rep = rep)
152-
153-
154-
toFormatOf : (f : Format) -> FormatOf f.Rep
155-
toFormatOf f = MkRefine f
149+
data FormatOf : (0 A : Type) -> Type where
150+
MkFormatOf : (f : Format) -> FormatOf f.Rep

0 commit comments

Comments
 (0)