ligo/test/test.ml

172 lines
3.2 KiB
OCaml
Raw Normal View History

2016-01-12 21:20:06 +04:00
module Monad_example = struct
module X : sig
type 'a t
2019-01-16 14:57:51 +04:00
2016-01-12 21:20:06 +04:00
module Let_syntax : sig
val return : 'a -> 'a t
2019-01-16 14:57:51 +04:00
2016-05-20 15:01:06 +04:00
module Let_syntax : sig
val return : 'a -> 'a t
2019-01-16 14:57:51 +04:00
val bind : 'a t -> f:('a -> 'b t) -> 'b t
val map : 'a t -> f:('a -> 'b) -> 'b t
val both : 'a t -> 'b t -> ('a * 'b) t
module Open_on_rhs : sig
val return : 'a -> 'a t
end
2016-05-20 15:01:06 +04:00
end
2016-01-12 21:20:06 +04:00
end
end = struct
type 'a t = 'a
2019-01-16 14:57:51 +04:00
2016-01-12 21:20:06 +04:00
let return x = x
2016-08-03 21:29:31 +04:00
let bind x ~f = f x
2016-01-12 21:20:06 +04:00
let map x ~f = f x
2019-01-16 14:57:51 +04:00
let both x y = x, y
2016-01-12 21:20:06 +04:00
module Let_syntax = struct
let return = return
2019-01-16 14:57:51 +04:00
2016-05-20 15:01:06 +04:00
module Let_syntax = struct
let return = return
2019-01-16 14:57:51 +04:00
let bind = bind
let map = map
let both = both
module Open_on_rhs = struct
let return = return
end
2016-05-20 15:01:06 +04:00
end
2016-01-12 21:20:06 +04:00
end
end
2016-05-20 15:01:06 +04:00
open X.Let_syntax
2016-01-12 21:20:06 +04:00
let _mf a : _ X.t =
let%bind_open x = a in
return (x + 1)
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
let _mf' a b c : _ X.t =
2019-01-16 14:57:51 +04:00
let%bind_open x = a
and y = b
and u, v = c in
2016-01-12 21:20:06 +04:00
return (x + y + (u * v))
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
let _mg a : _ X.t =
2018-08-13 13:25:18 +04:00
let%map x : int X.t = a in
2016-01-12 21:20:06 +04:00
x + 1
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
let _mg' a b c : _ X.t =
2019-01-16 14:57:51 +04:00
let%map x = a
and y = b
and u, v = c in
2016-01-12 21:20:06 +04:00
x + y + (u * v)
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
let _mh a : _ X.t =
match%bind_open a with
| 0 -> return true
| _ -> return false
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
let _mi a : _ X.t =
match%map a with
| 0 -> true
| _ -> false
2019-01-16 14:57:51 +04:00
;;
2016-08-31 19:09:28 +04:00
2019-01-16 14:57:51 +04:00
let _mif a : _ X.t = if%bind_open a then return true else return false
let _mif' a : _ X.t = if%map a then true else false
2016-01-12 21:20:06 +04:00
end
module Applicative_example = struct
module X : sig
type 'a t
2019-01-16 14:57:51 +04:00
2016-01-12 21:20:06 +04:00
module Let_syntax : sig
val return : 'a -> 'a t
2019-01-16 14:57:51 +04:00
2016-05-20 15:01:06 +04:00
module Let_syntax : sig
val return : 'a -> 'a t
2019-01-16 14:57:51 +04:00
val map : 'a t -> f:('a -> 'b) -> 'b t
val both : 'a t -> 'b t -> ('a * 'b) t
2016-05-20 15:01:06 +04:00
module Open_on_rhs : sig
val flag : int t
val anon : int t
end
2016-01-12 21:20:06 +04:00
end
end
end = struct
type 'a t = 'a
2019-01-16 14:57:51 +04:00
2016-01-12 21:20:06 +04:00
let return x = x
let map x ~f = f x
2019-01-16 14:57:51 +04:00
let both x y = x, y
2016-01-12 21:20:06 +04:00
module Let_syntax = struct
let return = return
2019-01-16 14:57:51 +04:00
2016-05-20 15:01:06 +04:00
module Let_syntax = struct
let return = return
2019-01-16 14:57:51 +04:00
let map = map
let both = both
2016-05-20 15:01:06 +04:00
module Open_on_rhs = struct
let flag = 66
let anon = 77
end
2016-01-12 21:20:06 +04:00
end
end
end
2016-05-20 15:01:06 +04:00
open X.Let_syntax
2016-01-12 21:20:06 +04:00
(* {[
let _af a : _ X.t =
let%bind x = a in (* "Error: Unbound value Let_syntax.bind" *)
return (x + 1)
]} *)
(* {[
let _af' a b c : _ X.t =
let%bind x = a and y = b and (u, v) = c in (* "Error: Unbound value Let_syntax.bind" *)
return (x + y + (u * v))
]} *)
let _ag a : _ X.t =
let%map x = a in
x + 1
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
let _ag' a b c : _ X.t =
2019-01-16 14:57:51 +04:00
let%map x = a
and y = b
and u, v = c in
2016-01-12 21:20:06 +04:00
x + y + (u * v)
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
(* {[
let _ah a : _ X.t =
match%bind a with (* "Error: Unbound value Let_syntax.bind" *)
| 0 -> return true
| _ -> return false
]} *)
let _ai a : _ X.t =
match%map a with
| 0 -> true
| _ -> false
2019-01-16 14:57:51 +04:00
;;
2016-01-12 21:20:06 +04:00
end
2018-06-07 14:39:27 +04:00
module Example_without_open = struct
let _ag a : _ Applicative_example.X.t =
let%map.Applicative_example.X.Let_syntax x = a in
x + 1
2019-01-16 14:57:51 +04:00
;;
2018-06-07 14:39:27 +04:00
end