diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2013-12-02 22:56:10 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2013-12-02 22:56:10 +0100 |
commit | 2b722cf3bdd267c999f25c4f1c2ebb4cc4d27cb4 (patch) | |
tree | 95a2fa4d0aac52f4a82e234276ce7ede15a8e8ff /ch04_suffixtree.hs | |
parent | 40860a46fa0a22cc376b015e36744c8573f92654 (diff) | |
download | haskell-2b722cf3bdd267c999f25c4f1c2ebb4cc4d27cb4.tar.gz haskell-2b722cf3bdd267c999f25c4f1c2ebb4cc4d27cb4.tar.bz2 haskell-2b722cf3bdd267c999f25c4f1c2ebb4cc4d27cb4.zip |
add other haskell files
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 |