Skip to content

Commit

Permalink
Encode/decode cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Sep 9, 2022
1 parent e129a83 commit 4e01ddc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions experiments/idris/src/Fathom/Closed/IndexedInductive.idr
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ namespace FormatOf

export
encode : {0 A, S : Type} -> (f : FormatOf A) -> Encode A (Colist S)
encode End () = Just []
encode (Pure x) (MkSing _) = Just []
encode End () = pure []
encode (Pure x) (MkSing _) = pure []
encode (Ignore f def) () = encode f def
encode (Repeat Z f) [] = Just []
encode (Repeat Z f) [] = pure []
encode (Repeat (S len) f) (x :: xs) =
[| encode f x <+> encode (Repeat len f) xs |]
encode (Bind f1 f2) (x ** y) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ namespace FormatOf

export
encode : {0 A : Type} -> (f : FormatOf A) -> Encode A ByteStream
encode End () = Just []
encode (Pure x) (MkSing _) = Just []
encode End () = pure []
encode (Pure x) (MkSing _) = pure []
encode (Ignore f def) () = encode f def
encode (Repeat Z f) [] = Just []
encode (Repeat Z f) [] = pure []
encode (Repeat (S len) f) (x :: xs) =
[| encode f x <+> encode (Repeat len f) xs |]
encode (Bind f1 f2) (x ** y) =
Expand Down
10 changes: 5 additions & 5 deletions experiments/idris/src/Fathom/Closed/InductiveRecursive.idr
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ namespace Format

export
encode : (f : Format) -> Encode (Rep f) (Colist a)
encode End () = Just []
encode (Pure x) (MkSing _) = Just []
encode End () = pure []
encode (Pure x) (MkSing _) = pure []
encode (Ignore f def) () = encode f def
encode (Repeat Z f) [] = Just []
encode (Repeat (S len) f) (x :: xs) = do
encode (Repeat Z f) [] = pure []
encode (Repeat (S len) f) (x :: xs) =
[| encode f x <+> encode (Repeat len f) xs |]
encode (Bind f1 f2) (x ** y) = do
encode (Bind f1 f2) (x ** y) =
[| encode f1 x <+> encode (f2 x) y |]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ namespace Format

export
encode : (f : Format) -> Encode (Rep f) ByteStream
encode End () = Just []
encode (Pure x) (MkSing _) = Just []
encode End () = pure []
encode (Pure x) (MkSing _) = pure []
encode (Ignore f def) () = encode f def
encode (Repeat Z f) [] = Just []
encode (Repeat Z f) [] = pure []
encode (Repeat (S len) f) (x :: xs) =
[| encode f x <+> encode (Repeat len f) xs |]
encode (Bind f1 f2) (x ** y) =
Expand Down
4 changes: 2 additions & 2 deletions experiments/idris/src/Fathom/Open/Record.idr
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace Format
decode = pure (MkSing x)

encode : Encode Rep ByteStream
encode (MkSing _) = Just []
encode (MkSing _) = pure []


public export
Expand Down Expand Up @@ -106,7 +106,7 @@ namespace Format
encode : Encode Rep ByteStream
encode = go len where
go : (len : Nat) -> Encode (Vect len f.Rep) ByteStream
go 0 [] = Just []
go 0 [] = pure []
go (S len) (x :: xs) =
[| f.encode x <+> go len xs |]

Expand Down

0 comments on commit 4e01ddc

Please sign in to comment.