[Haskell-cafe] Re: Inferred typing?

Achim Schneider barsoap at web.de
Tue May 12 07:24:16 EDT 2009


michael rice <nowgate at yahoo.com> wrote:

> In the code below, is the type returned by the return functions
> inferred from the result type in the function type signature, i.e.,
> just change the result type to Maybe Int and the code will return a
> Maybe monad, (Just 4), instead of a List monad?
> 
Yes.

Prelude> :m Control.Monad
Prelude Control.Monad> let fn l = mzero `mplus` (return (head l))
  `mplus` (return (last l)) 
Prelude Control.Monad> fn [1,3] :: Maybe Int 
Just 1
Prelude Control.Monad> fn [1,3] :: Maybe Float
Just 1.0
Prelude Control.Monad> fn [1,2,3] :: [Int]
[1,3]

-- 
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.




More information about the Haskell-Cafe mailing list