diff options
Diffstat (limited to 'ch04_suffixtree.hs')
-rw-r--r-- | ch04_suffixtree.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ch04_suffixtree.hs b/ch04_suffixtree.hs new file mode 100644 index 0000000..a677ea4 --- /dev/null +++ b/ch04_suffixtree.hs @@ -0,0 +1,28 @@ +import Data.List (tails) + +suffixes :: [a] -> [[a]] +suffixes xs@(_:xs') = xs : suffixes xs' +-- as pattern. +-- binds xs to the value on the right of the @ +suffixes _ = [] + +-- same thing without as-pattern +-- This will do a copy of the data, the as-pattern doesn't + +suffixesNoAs (x:xs) = (x:xs) : suffixesNoAs xs +suffixesNoAs _ = [] + +-- even better +suffixes2 :: [a] -> [[a]] +suffixes2 xs = init (tails xs) + + +compose :: (b -> c) -> (a -> b) -> a -> c +compose f g x = f (g x) + +suffixes3 xs = compose init tails xs + +suffixes4 = compose init tails + +-- no need to invent the compose function +suffixes5 = init . tails |