[Haskell-cafe] regex-applicative library needs your help! (algorithmic challenge)
roma at ro-che.info
Sun Sep 18 11:09:22 CEST 2011
* Anton Tayanovskyy <anton.tayanovskyy at gmail.com> [2011-09-17 22:11:00-0400]
> By the way, can Haskell have a type that admits regular expression and
> only those? I mostly do ML these days, so trying to write up a regex
> types in Haskell I was unpleasantly surprised to discover that there
> are all sorts of exotic terms inhabiting it, which I did not have to
> worry about in ML. Besides `undefined` you can have for terms that try
> to define a grammar with nested parentheses. Using regex-applicative
> expr = ... <|> pure (\ _ x _ -> x) <*> sym "(" <*> expr <*> sym ")"
> Is this the so-called 'paucity of types' ? What do you do, as a
> library designer? Return bottom or try to detect and error out for
> these kind of values?
>  http://existentialtype.wordpress.com/tag/recursion/
Essentially, this is an "infinite" regular expression.
I think it'd be possible to enforce this on the type level. (There was a
thread here some time ago about a type of finite lists.)
If a library can work with such infinite trees, and the user is happy
with resulting performance, then, why not.
For example, this is the case with weighted-regexp library, and also
with the first (and buggy) version of regex-applicative .
Otherwise, just let the user know that this function doesn't work with
infinite data structures. Note that in the presence of referential
transparency (i.e. without StableNames or similar tools) it is not
possible to decide at runtime if a value is circular or not.
Roman I. Cheplyaka :: http://ro-che.info/
More information about the Haskell-Cafe