Skip to content

Commit 53d50c6

Browse files
committed
Make Decode type match Source more closely
1 parent 6e8660a commit 53d50c6

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

experiments/idris/src/Fathom/Base.idr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ parameters (Source : Type, Target : Type)
2121

2222
||| Decoders consume a _target value_ and produce either:
2323
|||
24-
||| - a _source value_ and _remaining target value_
24+
||| - a _source value_
2525
||| - or nothing if in error occurred
2626
|||
2727
||| @ Source The type of source values (usually an in-memory data structure)
28-
||| @ Target The type of target values (usually a byte-stream)
2928
public export
3029
Decode : Type
31-
Decode = Target -> Maybe (Source, Target)
30+
Decode = Target -> Maybe Source
3231

3332
||| Encoders take a _source value_ and produce either:
3433
|||

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public export
4343
---------------------------
4444

4545
export
46-
decode : {0 Rep : Type} -> (f : FormatOf Rep) -> Decode Rep (Colist a)
46+
decode : {0 Rep : Type} -> (f : FormatOf Rep) -> Decode (Rep, Colist a) (Colist a)
4747
decode End [] = Just ((), [])
4848
decode End (_::_) = Nothing
4949
decode Fail _ = Nothing

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public export
9595

9696

9797
export
98-
decode : (f : Format) -> Decode (Rep f) (Colist a)
98+
decode : (f : Format) -> Decode (Rep f, Colist a) (Colist a)
9999
decode End [] = Just ((), [])
100100
decode End (_::_) = Nothing
101101
decode Fail _ = Nothing

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public export
2626
record CustomFormat where
2727
constructor MkCustomFormat
2828
Rep : Type
29-
decode : Decode Rep ByteStream
29+
decode : Decode (Rep, ByteStream) ByteStream
3030
encode : Encode Rep ByteStream
3131

3232

@@ -61,7 +61,7 @@ mutual
6161

6262

6363
export
64-
decode : (f : Format) -> Decode (Rep f) ByteStream
64+
decode : (f : Format) -> Decode (Rep f, ByteStream) ByteStream
6565
decode End [] = Just ((), [])
6666
decode End (_::_) = Nothing
6767
decode Fail _ = Nothing

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public export
2828
record Format where
2929
constructor MkFormat
3030
Rep : Type
31-
decode : Decode Rep BitStream
31+
decode : Decode (Rep, BitStream) BitStream
3232
encode : Encode Rep BitStream
3333

3434

@@ -43,7 +43,7 @@ end = MkFormat { Rep, decode, encode } where
4343
Rep : Type
4444
Rep = Unit
4545

46-
decode : Decode Rep BitStream
46+
decode : Decode (Rep, BitStream) BitStream
4747
decode [] = Just ((), [])
4848
decode (_::_) = Nothing
4949

@@ -57,7 +57,7 @@ fail = MkFormat { Rep, decode, encode } where
5757
Rep : Type
5858
Rep = Void
5959

60-
decode : Decode Rep BitStream
60+
decode : Decode (Rep, BitStream) BitStream
6161
decode _ = Nothing
6262

6363
encode : Encode Rep BitStream
@@ -70,7 +70,7 @@ pure x = MkFormat { Rep, decode, encode } where
7070
Rep : Type
7171
Rep = Sing x
7272

73-
decode : Decode Rep BitStream
73+
decode : Decode (Rep, BitStream) BitStream
7474
decode buffer = Just (MkSing x, buffer)
7575

7676
encode : Encode Rep BitStream
@@ -83,7 +83,7 @@ skip f def = MkFormat { Rep, decode, encode } where
8383
Rep : Type
8484
Rep = ()
8585

86-
decode : Decode Rep BitStream
86+
decode : Decode (Rep, BitStream) BitStream
8787
decode buffer = do
8888
(x, buffer') <- f.decode buffer
8989
Just ((), buffer')
@@ -98,9 +98,9 @@ repeat len f = MkFormat { Rep, decode, encode } where
9898
Rep : Type
9999
Rep = Vect len f.Rep
100100

101-
decode : Decode Rep BitStream
101+
decode : Decode (Rep, BitStream) BitStream
102102
decode = go len where
103-
go : (len : Nat) -> Decode (Vect len f.Rep) BitStream
103+
go : (len : Nat) -> Decode (Vect len f.Rep, BitStream) BitStream
104104
go 0 buffer = Just ([], buffer)
105105
go (S len) buffer = do
106106
(x, buffer') <- f.decode buffer
@@ -121,7 +121,7 @@ bind f1 f2 = MkFormat { Rep, decode, encode } where
121121
Rep : Type
122122
Rep = (x : f1.Rep ** (f2 x).Rep)
123123
124-
decode : Decode Rep BitStream
124+
decode : Decode (Rep, BitStream) BitStream
125125
decode buffer = do
126126
(x, buffer') <- f1.decode buffer
127127
(y, buffer'') <- (f2 x).decode buffer'

0 commit comments

Comments
 (0)