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

From: Michael Hanus <>
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,

curry mailing list
Received on Fr Mai 16 2008 - 18:38:20 CEST

This archive was generated by hypermail 2.3.0 : So Aug 07 2022 - 07:15:17 CEST