Re: Curry patterns

From: Wolfgang Lux <wlux_at_uni-muenster.de>
Date: Wed, 15 Apr 2009 17:29:45 +0200

Nikolay Orlyuk wrote:

> I.e. if you want some kind of semideterministic (I like this term
> from Mercury) function you should wrap it like:
> parse_semidet s | once (parse s =:= r) = r where r free
> Sorry.
> parse_semidet s = findfirst (parse s =:=)

Well, almost. You should eta-expand findfirst's argument, i.e.,
   parse_semidet s = findfirst (\r -> parse s =:= r)
Otherwise, the non-deterministic evaluation of (parse s) will not be
encapsulated under MCC.

Wolfgang

P.S.: In case you wonder why eta-expansion is necessary, consider
   map (const (0?1)) [(),()]
versus
   map (\x -> const (0?1) x) [(),()]
The former yields results [0,0] and [1,1] because the expression (0?
1) is evaluated just once, whereas the latter has four solutions,
viz. [0,0], [0,1], [1,0], and [1,1], since the expression (0?1) is
evaluated for each element of the list.
_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Do Apr 16 2009 - 09:11:13 CEST

This archive was generated by hypermail 2.3.0 : Do Jun 20 2024 - 07:15:10 CEST