I am happy to announce the release of Tyre 1.0.
This release makes big changes to the typing: there is a whole host of far more practical combinators allowing you to write code like in a parser combinator library :
let url =
let+ scheme = opt (const Http (str "http") <|> const Https (str "http") <* str "://")
and+ host = rep_any
and+ port = opt (str ":" *> pos_int)
and+ path = list (str "/" *> rep_any)
and+ _ = str "/"
in
(scheme, host, port, path)
(this is not a correct url parser by any means, its just to give an idea of how you can use this lib)
This does not allow you to use eval, because only one direction of the conversion is given (there is no code to convert from a url tuple). However in the cases where you don’t need eval this is far easier to write. The difference is typed, you can’t get runtime error by calling eval on the wrong regex.
There are also convencience changes such as charset and the matched_string function, that reduce the need to insert Re bits in your regexp.
Here is the full changelog:
- Introduce charsets: contrary to
Re, they have a different type from regex. - Type the difference between regexps that can be evaluated reversed and the
ones that cannot:(evaluable, 'a) Tyre.tand(non_evaluable, 'a) Tyre.t. - Introduce alias
type patternfor(non_evaluable, 'a) Tyre.t. - Introduce
val lift : ('a -> string) -> 'a pattern -> ('e, 'a) tto transform
a pattern into an expression by giving an explicit conversion function.
Alsoliftppthat does the same with better performance by usingFormat. - Introduce
val unlift : (evaluable, 'a) t -> 'a pattern. - Introduce
val either: ('e, 'a) Tyre.t -> ('e, 'b) Tyre.t -> ('e, ('a, 'b) Either.t) Tyre.t. - Change the type of
altto(_, 'a) t -> (_, 'a) t -> 'a pattern. Previous
users ofaltshould switch toeither. - Introduce
val alt_eval: ('a -> [`Left | `Right]) -> ('e, 'a) t -> ('e, 'a) t -> ('e, 'a) t
This has flat typing but is compatible witheval. - Operators:
<|>isalt,<||>iseither. - Introduce
val map : ('a -> 'b) -> (_, 'a) t -> 'b patternand its
corresponding operators:let+and<$>. - Introduce
(and+)which is an alias ofseq. - Introduce
val app: ('e, 'a -> 'b) t -> ('e, 'a) t -> 'b patternand its
corresponding operator<*> - Introduce
val matched_string : (_, 'a) t -> (_, string) tthat discards the
computed value and just return the string that was matched. - Drop dependency on
Resultlibrary. Stdlib is now used. - Introduce
val rep_charset: Charset.t -> (_, string) t, and shortcut
val rep_any: (_, string) t.