4 ms·
http://paste.lisp.org/display/74007 http://paste.lisp.org/display/74007 let Right x = paramTree [("a[x]","b"),("a[b]","c"), ("a[b][c]","d"),("bc[de]","
by shrughes 18y ago
http://paste.lisp.org/display/74007 http://paste.lisp.org/display/74007
let Right x = paramTree [("a[x]","b"),("a[b]","c"),
("a[b][c]","d"),("bc[de]","f")] in putStrLn (drawTree x)
{ "a" => { "b" => <conflict>, "x" => "b" }, "bc" => {
"de" => "f" } }
- eru 18y agoInteresting. Could you have implemented drawTree with Language.Haskell.Pretty? Also I get the following error with ghc: yc.hs:35:34: No instance for (Monad (Either String)) arising from a use of `mapM' at yc.hs:35:34-52 Possible fix: add an instance declaration for (Monad (Either String)) In a 'do' expression: keys <- mapM parseKey names In the expression: do keys <- mapM parseKey names return (toTree (zip keys values)) In the definition of `paramTree': paramTree nameValues = do keys <- mapM parseKey names return (toTree (zip keys values)) where (names, values) = unzip nameValues (Edit: I'm sorry that the error message's whitespace gets messed up here.) Also your groupings function is only used in conjunction with Data.Map.fromList. Did you consider using something like Data.Map.fromListWith (++) instead? Of course you'd have to wrap your would-be Map values in singleton lists first.
- shrughes 18y agoWhat version of GHC (or of the libraries) do you have? (Either String) should be a monad as specified through Control.Monad.Error: instance Error e => Monad (Either e) where ... I didn't consider Data.Map.fromListWith; I didn't know about it. (Thanks.)