Commit 3e63826d authored by Kim Nguyễn's avatar Kim Nguyễn
Browse files

Add flatten test case.

parent d601e757
Pipeline #178 failed with stages
in 2 minutes and 21 seconds
......@@ -6,6 +6,14 @@
(rule (alias addrbook) (action (diff addrbook.exp addrbook.out)))
; end: addrbook.cd
; begin: flatten.cd
(rule (deps flatten.cd) (target flatten.cdo)
(action (ignore-outputs (with-accepted-exit-codes 0 (run cduce --compile %{deps})))))
(rule (deps flatten.cdo) (target flatten.out)
(action (ignore-stderr (with-stdout-to %{target} (with-accepted-exit-codes 0 (run cduce --run %{deps}))))))
(rule (alias flatten) (action (diff flatten.exp flatten.out)))
; end: flatten.cd
; begin: integers.cd
(rule (deps integers.cd) (target integers.cdo)
(action (ignore-outputs (with-accepted-exit-codes 0 (run cduce --compile %{deps})))))
......@@ -74,6 +82,7 @@
(deps
(source_tree ../../common)
(alias addrbook)
(alias flatten)
(alias integers)
(alias lazy)
(alias map_even)
......
type Tree('a) = ('a\[Any*]) | [ (Tree('a))* ]
let flatten ( (Tree('a)) -> ['a*])
let flatten ( Tree('a) -> ['a*])
| [] -> []
| [h ; t] -> (flatten h)@(flatten t)
| x -> [x]
;;
(*
Ce qui est intéressant est que Any <: Tree(Any) ... donc on peux
appliquer flatten à n'importe quelle expressions:
......@@ -14,3 +16,6 @@ appliquer flatten à n'importe quelle expressions:
# flatten [ 3 'r' [ 4 [ `true 5 ]] [ "quo" [[ `false ] "stop" ] ] ];;
- : [ (Bool | 3--5 | 'o'--'u')* ] = [ 3 'r' 4 true 5 'quo' false 'stop' ]
*)
let _ = print (string_of
(flatten [ 3 'r' [ 4 [ `true 5 ]] [ "quo" [[ `false ] "stop" ] ] ]))
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment