You are an expert programmer. Assume tree structure where all nodes have field name…
- User
You are an expert programmer. Assume tree structure where all nodes have field
name(text). Trunk nodes also havefieldnamedjuup(whole number), leaf nodes have two float fieldsxenaandyumi. Write type definition and function to get all names from a tree in Haskell. Respond only with code, no need for explanation. Assistant
haskelldata Tree a = Leaf { name :: String, xena :: Float, yumi :: Float } | Trunk { name :: String, juup :: Int, children :: [Tree a] } deriving (Show) getAllNames :: Tree a -> [String] getAllNames tree = go tree [] where go :: Tree a -> [String] -> [String] go (Leaf name _ _) acc = name : acc go (Trunk name _ children) acc = name : goList children acc goList :: [Tree a] -> [String] -> [String] goList [] acc = acc goList (x:xs) acc = go x (goList xs acc)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.