On 5/28/08, Evan Laforge <[EMAIL PROTECTED]> wrote: > I have two related questions: > > #1 > > I'm getting some annoying type errors that I don't fully understand, > and wind up having to do a workaround that I don't totally like. > Here's a simplified version of my situation: > > data Ambi m = Ambi { > ambi_monad :: m Int > , ambi_int :: Int > } > > some_ambi :: Monad m => Ambi m > some_ambi = Ambi (return 5) 10 > > ambi_table :: Monad m => [(String, Ambi m)] > ambi_table = [("default", some_ambi)] > > get_int :: String -> Maybe Int > get_int sym = fmap ambi_int (lookup sym ambi_table) > > ----------- > > get_int produces: > Ambiguous type variable `m' in the constraint: > `Monad m' arising from a use of `ambi_table' at ambi.hs:13:40-49
You can let the caller choose "m": get_int :: Monad m => m () -> String -> Maybe Int get_int _ sym = fmap ambi_int (lookup sym ambi_table) which can be called like so: get_int (error "shouldn't evaluate" :: IO ()) "test" _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe