In short, you cannot. What if your main were:
main = getArgs >>= print . first_h The compiler doesn't know the difference and so it needs a type. Simple fix: > main = print (first_h ([] :: [Char])) -- Hal Daume III "Computer science is no more about computers | [EMAIL PROTECTED] than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume On Fri, 17 May 2002 [EMAIL PROTECTED] wrote: > Hello, > I am writing a function which returns an exception/error string should an >unexpected parameter is passed in. Borrowing from the Maybe module I have the >following: > ------------------------------------------------------------ > data Result a = Ex String | Value a deriving Show > > -- Testing the Result a type > first_h :: [a] -> Result a > first_h [] = Ex "No list" > first_h (x:xs) = Value x > > -- Trying out the first_h > main :: IO() > main = print (first_h []) > ------------------------------------------------------------ > > Which the compiler complains: > > Ambiguous type variable(s) `a' in the constraint `Show a' > arising from use of `print' at atype.hs:8 > In the definition of `main': print (first_h []) > > This is understandable since it is unable to unify the empty list with a concrete >list of type 'a' i.e. there are an infinite types which would match. My question is >how can I indicate to the compiler that it does not matter which type the empty list >is since the return result is of a concreate type. > > Thanks > > Tee > _______________________________________________ > Haskell-Cafe mailing list > [EMAIL PROTECTED] > http://www.haskell.org/mailman/listinfo/haskell-cafe > _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
