Created
March 27, 2014 00:08
-
-
Save romanofski/9796825 to your computer and use it in GitHub Desktop.
traversing method in haskell (errors included ;))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell #-} | |
import Test.QuickCheck | |
import Test.QuickCheck.All | |
import Data.List | |
import Data.List.Split | |
-- | |
-- since lists are homogenous, we'll need something which can resemble | |
-- a tree | |
-- | |
data NestedList a = Elem a | List [NestedList a] deriving Show | |
-- traversing | |
-- this little utility method takes a path and traverses the given list | |
-- with identifiers | |
traverse:: String -> NestedList [String] -> String | |
traverse p (List []) = "" | |
traverse p (Elem x) = x | |
traverse p (List x:xs) | |
| x == h = traverse restpath (List xs) | |
| otherwise = x | |
where h = head ys | |
ys = splitOn "/" p | |
restpath = foldr (\x a -> x ++ a) [] (tail ys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment