Skip to content

Instantly share code, notes, and snippets.

@LukaHorvat
Created October 19, 2015 14:28
Show Gist options
  • Save LukaHorvat/5e9c3b2dacbc324be7ba to your computer and use it in GitHub Desktop.
Save LukaHorvat/5e9c3b2dacbc324be7ba to your computer and use it in GitHub Desktop.
data Node = Value Int | List [Node] | Sequence [Node]
steps :: Node -> [[Int]]
steps (Value x) = [[x]]
steps (List ns) = case substeps of
[] -> []
(x : xs) -> x ++ concat (zipWith prepend lastStates xs)
where substeps = map steps ns
lastStates = scanl1 (++) $ map last substeps
prepend pref ss = map (pref ++) ss
steps (Sequence ns) = concatMap steps ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment