Skip to content

Commit 6487cea

Browse files
committed
Switch to using records for singletons
1 parent 711c66a commit 6487cea

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

experiments/idris/src/Fathom/Base.idr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,29 @@ record Refine (0 A : Type) (0 P : A -> Type) where
1919
||| The wrapped value
2020
value : A
2121
||| The proof of the proposition
22-
0 prf : P value
22+
{auto 0 prf : P value}
2323

2424
||| Refine a value with a proposition
2525
public export
2626
refine : {0 A : Type} -> {0 P : A -> Type} -> (value : A) -> {auto 0 prf : P value} -> Refine A P
27-
refine value {prf} = MkRefine { value, prf }
27+
refine value = MkRefine { value }
2828

2929

3030
||| Singleton types
3131
|||
3232
||| Inspired by [this type](https://agda.readthedocs.io/en/v2.5.4.1/language/with-abstraction.html#the-inspect-idiom)
3333
||| from the Agda docs.
3434
public export
35-
data Sing : {0 A : Type} -> (x : A) -> Type where
36-
MkSing : {0 A : Type} -> {0 x : A} -> (0 y : A) -> {auto 0 prf : x = y} -> Sing x
35+
record Sing {0 A : Type} (x : A) where
36+
constructor MkSing
37+
0 value : A
38+
{auto 0 prf : x = value}
39+
40+
41+
||| Convert a singleton back to its underlying value
42+
public export
43+
sing : {0 A : Type} -> {0 x : A} -> (0 value : A) -> {auto 0 prf : x = value} -> Sing x
44+
sing value = MkSing { value }
3745

3846
||| Convert a singleton back to its underlying value
3947
public export

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ decode End [] = Just ((), [])
3737
decode End (_::_) = Nothing
3838
decode Fail _ = Nothing
3939
decode (Pure x) buffer =
40-
Just (MkSing x, buffer)
40+
Just (sing x, buffer)
4141
decode (Skip f _) buffer = do
4242
(x, buffer') <- decode f buffer
4343
Just ((), buffer')

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ decode End [] = Just ((), [])
8787
decode End (_::_) = Nothing
8888
decode Fail _ = Nothing
8989
decode (Pure x) buffer =
90-
Just (MkSing x, buffer)
90+
Just (sing x, buffer)
9191
decode (Skip f _) buffer = do
9292
(x, buffer') <- decode f buffer
9393
Just ((), buffer')
@@ -173,7 +173,7 @@ orPure' False _ def = refine (Pure def)
173173

174174
foo : (cond : Bool) -> (f : Format) -> Rep f -> Format
175175
foo cond f def = case orPure cond (toFormatOf f) def of
176-
MkRefine f' prf =>
176+
MkRefine f' {prf} =>
177177
Bind f' (\x => case cond of
178178
True => ?todo1
179179
False => ?todo2)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ decode End [] = Just ((), [])
6464
decode End (_::_) = Nothing
6565
decode Fail _ = Nothing
6666
decode (Pure x) buffer =
67-
Just (MkSing x, buffer)
67+
Just (sing x, buffer)
6868
decode (Skip f _) buffer = do
6969
(x, buffer') <- decode f buffer
7070
Just ((), buffer')
@@ -150,7 +150,7 @@ orPure' False _ def = refine (Pure def)
150150

151151
foo : (cond : Bool) -> (f : Format) -> Rep f -> Format
152152
foo cond f def = case orPure cond (toFormatOf f) def of
153-
MkRefine f' prf =>
153+
MkRefine f' {prf} =>
154154
Bind f' (\x => case cond of
155155
True => ?todo1
156156
False => ?todo2)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pure x = MkFormat { Rep, decode, encode } where
5757
Rep = Sing x
5858

5959
decode : Decode Rep BitStream
60-
decode buffer = Just (MkSing x, buffer)
60+
decode buffer = Just (sing x, buffer)
6161

6262
encode : Encode Rep BitStream
6363
encode (MkSing _) buffer = Just buffer

0 commit comments

Comments
 (0)