Re: Two to Three Ways to write an unsafe type cast without importing Unsafe

From: Michael Hanus <mh_at_informatik.uni-kiel.de>
Date: Fri, 16 May 2008 18:34:31 +0200

Wolfgang Lux wrote:
> You should be aware that this sort of restriction seriously
> limits the abilities of using logical style definitions in Curry.
> Consider the following innocuous little goal
>
> last [(+), (-), (*)] 7 6
>
> The result of this goal is either 42 or a runtime error depending
> on whether last is defined in a purely functional style
> last [x] = x
> last (_:x:xs) = last (x:xs)
> or with a function pattern
> last (_ ++ [x]) = x

If you use function patterns, it is not a problem,
since the function pattern

  last (_ ++ [x]) = x

is considered as an abbreviation for the infinite set of rules

  last [x] = x
  last [_,x] = x
  last [_,_,x] = x
  ...

i.e., variables in a function pattern are considered as pattern
variables which can be bound to partial functions. However,
if one defines last in a logic style as

  last xs | ys++[x] =:= xs = x where ys,x free

then you are right that the strict equality would cause
a run-time error for the goal above.

Best regards,

Michael
_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Fr Mai 16 2008 - 18:38:20 CEST

This archive was generated by hypermail 2.3.0 : Do Feb 01 2024 - 07:15:08 CET