Intersperse.curry 1 KB
Newer Older
Michael Hanus 's avatar
Michael Hanus committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
--- Example from:
--- 
--- Christiansen, J. and Seidel, D.: Minimally strict polymorphic functions
--- Proc. of the 13th International Symposium on Principle and Practice
--- of Declarative Programming (PPDP'11), pp. 53-64
--- DOI: 10.1145/2003476.2003487

import Test.Prop

--- Definition of `intersperse` from module `List`.
intersperse1 :: a -> [a] -> [a]
intersperse1 _   []           = []
intersperse1 _   [x]          = [x]
intersperse1 sep (x:xs@(_:_)) = x : sep : intersperse1 sep xs

--- Less strict definition.
intersperse2 :: a -> [a] -> [a]
intersperse2 _   []     = []
intersperse2 sep (x:xs) = x : go xs
 where
  go []     = []
  go (y:ys) = sep : y : go ys


25
-- These operations are not equivalent (falsified by 43th test):
Michael Hanus 's avatar
Michael Hanus committed
26
intersperseEquiv = intersperse1 <=> intersperse2
27 28 29 30 31 32

-- These operations are not equivalent (falsified by 4th test):
intersperseEquiv'TERMINATE = intersperse1 <=> intersperse2

-- Ground equivalence testing is successful:
intersperseEquiv'GROUND x xs = intersperse1 x xs <~> intersperse2 x xs