On Sun, Jan 17, 2010 at 7:02 AM, Stephen Tetley <stephen.tetley@gmail.com> wrote:
I wouldn't use read instead something either a simple function:
> verb :: String -> Maybe Verb
> verb "Go" = Just Go
> verb "Get" = Just Get
> verb _ = Nothing
Or possible a Map:
> verb2 :: String -> Maybe Verb
> verb2 s = Map.lookup s verb_map
> verb_map :: Map.Map String Verb
> verb_map = Map.fromAscList [ ("Go", Go), ("Get", Get) {- .. -} ]
You could then do more about say case sensitivity - e.g. add ("get",Get) etc
or always convert to upper before querying the map.
> verb3 :: String -> Maybe Verb
> verb3 s = Map.lookup (map toUpper s) verb_map2
> verb_map2 :: Map.Map String Verb
> verb_map2 = Map.fromAscList [ ("GO", Go), ("GET", Get) {- .. -} ]
Best wishes
Stephen
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe