Skip to content

Commit 14c3cef

Browse files
committed
feat(bidi-combinators): Add value type alias
1 parent a956c55 commit 14c3cef

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

lang-bidi-combinators/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let width x = x.width
2323
let height x = x.height
2424
let data x = x.data
2525
26-
let format : (t, t) Format.t =
26+
let format : t Format.value =
2727
let open Format.Syntax in
2828
2929
let* width = width @= Format.int16_be

lang-bidi-combinators/examples/image.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let width x = x.width
1010
let height x = x.height
1111
let data x = x.data
1212

13-
let format : (t, t) Format.t =
13+
let format : t Format.value =
1414
let open Format.Syntax in
1515

1616
let* width = width @= Format.int16_be

lang-bidi-combinators/examples/image_with_header.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Header = struct
1010
let width x = x.width
1111
let height x = x.height
1212

13-
let format : (t, t) Format.t =
13+
let format : t Format.value =
1414
let open Format.Syntax in
1515

1616
let+ width = width @= Format.int16_be
@@ -28,7 +28,7 @@ type t = {
2828
let header x = x.header
2929
let data x = x.data
3030

31-
let format : (t, t) Format.t =
31+
let format : t Format.value =
3232
let open Format.Syntax in
3333

3434
let* header = header @= Header.format in

lang-bidi-combinators/format.ml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ type ('c, 'a) t = {
99
encode : ('c, 'a) Encoder.t;
1010
}
1111

12+
type 'a value = ('a, 'a) t
13+
1214
let ( let+ ) x f = Option.map f x
1315
let ( let* ) = Option.bind
1416

@@ -75,37 +77,37 @@ open Sized_numbers
7577

7678
(* Integer conversion formats *)
7779

78-
let int_to_i32 : (int, int) t -> (int32, int32) t =
80+
let int_to_i32 : int value -> int32 value =
7981
dimap Int32.of_int Int32.to_int
8082

81-
let int_to_i64 : (int, int) t -> (int64, int64) t =
83+
let int_to_i64 : int value -> int64 value =
8284
dimap Int64.of_int Int64.to_int
8385

8486

8587
(* Integer formats *)
8688

87-
let int8 : (int, int) t = (* FIXME: int8 *)
89+
let int8 : int value = (* FIXME: int8 *)
8890
let decode buf pos = if pos < Bytes.length buf then Some (Bytes.get_int8 buf pos, pos + 1) else None
8991
and encode buf c = Buffer.add_int8 buf c; Some c in
9092
{ decode; encode }
9193

92-
let int16_be : (int, int) t = (* FIXME: int16 *)
94+
let int16_be : int value = (* FIXME: int16 *)
9395
let open Syntax in
9496

9597
let+ b0 = int8 |> dimap (fun x -> x lsl 8) (fun x -> x lsr 8)
9698
and+ b1 = int8 in
9799

98100
b0 lor b1
99101

100-
let int16_le : (int, int) t = (* FIXME: int16 *)
102+
let int16_le : int value = (* FIXME: int16 *)
101103
let open Syntax in
102104

103105
let+ b0 = int8
104106
and+ b1 = int8 |> dimap (fun x -> x lsl 8) (fun x -> x lsr 8) in
105107

106108
b0 lor b1
107109

108-
let int32_be : (int32, int32) t =
110+
let int32_be : int32 value =
109111
let open Syntax in
110112
let open Int32.O in
111113

@@ -116,7 +118,7 @@ let int32_be : (int32, int32) t =
116118

117119
b0 lor b1 lor b2 lor b3
118120

119-
let int32_le : (int32, int32) t =
121+
let int32_le : int32 value =
120122
let open Syntax in
121123
let open Int32.O in
122124

@@ -127,7 +129,7 @@ let int32_le : (int32, int32) t =
127129

128130
b0 lor b1 lor b2 lor b3
129131

130-
let int64_be : (int64, int64) t =
132+
let int64_be : int64 value =
131133
let open Syntax in
132134
let open Int64.O in
133135

@@ -142,7 +144,7 @@ let int64_be : (int64, int64) t =
142144

143145
b0 lor b1 lor b2 lor b3 lor b4 lor b5 lor b6 lor b7
144146

145-
let int64_le : (int64, int64) t =
147+
let int64_le : int64 value =
146148
let open Syntax in
147149
let open Int64.O in
148150

@@ -162,7 +164,7 @@ module List = struct
162164

163165
open Syntax
164166

165-
let repeat_len (type a) (elem : (a, a) t) (len : int) : (a list, a list) t =
167+
let repeat_len (type a) (elem : a value) (len : int) : a list value =
166168
let rec repeat_len i =
167169
if i < len then
168170
(* FIXME: List.hd and List.tl fail on the empty list*)
@@ -178,7 +180,7 @@ end
178180

179181
module Array = struct
180182

181-
let repeat_len (type a) (elem : (a, a) t) (len : int) : (a array, a array) t =
183+
let repeat_len (type a) (elem : a value) (len : int) : a array value =
182184
(* FIXME: No clue if this actually works... and it’s really ugly! write some tests! *)
183185
let decode buf pos =
184186
if len <= 0 then Some ([||], pos) else

0 commit comments

Comments
 (0)