Commit d601e757 authored by Giuseppe Castagna's avatar Giuseppe Castagna
Browse files

added flatten

parent b471a23f
Pipeline #177 passed with stages
in 4 minutes and 14 seconds
type Tree('a) = ('a\[Any*]) | [ (Tree('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:
# flatten [ 3 'r' [ 4 [ `true 5 ]] [ "quo" [[ `false ] "stop" ] ] ];;
- : [ (Bool | 3--5 | 'o'--'u')* ] = [ 3 'r' 4 true 5 'quo' false 'stop' ]
*)
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