Skip to content

Instantly share code, notes, and snippets.

@romanofski
Created March 27, 2014 00:08
Show Gist options
  • Save romanofski/9796825 to your computer and use it in GitHub Desktop.
Save romanofski/9796825 to your computer and use it in GitHub Desktop.
traversing method in haskell (errors included ;))
{-# 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