data Record a = MkRecordV [(String, Either a (Record a))] deriving Show toPathVals :: Record a -> [([String], a)] toPathVals (MkRecordV l) = case l of [] -> [] (x : xs) -> case snd x of Left v -> [([fst x], v)] ++ toPathVals (MkRecordV xs) Right (MkRecordV l') -> map (\pair -> ([fst x] ++ fst pair, snd pair)) (toPathVals (MkRecordV l')) myRecord :: Record Int myRecord = MkRecordV [("fst", Left 7), ("snd", Right $ MkRecordV [("third", Left 100), ("fourth", Left 51)])] main = print $ toPathVals myRecord this will work, but I am annoyed that I can't find the general principle