There is a piece of source-code that originated in an answer to another one of my questions,
infFromPrefix :: Eq a => ([a] -> [a]) -> [a] -> [a]
infFromPrefix rules prefix = inf where
inf = prefix ++ case stripPrefix prefix (rules inf) of
Just suffix -> suffix
Nothing -> error "Substitution does not preserve prefix"
where I am pretty sure that inf
must be a closure as it has access to variables from its enclosing scope in the sense that it uses the parameters passed to infFromPrefix
, but am unsure since essentially infFromPrefix
and inf
is the same function, the inf
only allows
a more succinct definition. An equivalent definition would be
infFromPrefix rules prefix = prefix ++ case stripPrefix prefix (rules $ infFromPrefix rules prefix) of
Just suffix -> suffix
Nothing -> error "Substitution does not preserve prefix"
Am I correct, is inf
a closure?