<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hi Tillman,<br><br>Prelude Control.Monad Control.Monad.Instances Control.Applicative> let f = \x -> x:[]<br>Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t f<br>f :: a -> [a]<br>Prelude Control.Monad Control.Monad.Instances Control.Applicative> let g = \x -> Just x<br>Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t g<br>g :: a -> Maybe a<br><br>Prelude Control.Monad Control.Monad.Instances Control.Applicative> :t z<br>z :: Integer -> Integer<br><br>Prelude Control.Monad Control.Monad.Instances Control.Applicative Data.Char> :t y<br>y :: Char -> Int<br><br><br>Can you think of a situation for<br><br> \x -> f x<br><br>that would require x to have a declared type, or is it always inferred by the type of f?<br><br><br>Michael<br><br><br>--- On <b>Wed, 9/1/10, Tillmann Rendel
<i><rendel@Mathematik.Uni-Marburg.de></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Tillmann Rendel <rendel@Mathematik.Uni-Marburg.de><br>Subject: Re: [Haskell-cafe] On to applicative<br>To: "michael rice" <nowgate@yahoo.com><br>Cc: haskell-cafe@haskell.org<br>Date: Wednesday, September 1, 2010, 5:28 PM<br><br><div class="plainMail">michael rice wrote:<br>> Prelude Data.Either> let m = Just 7<br>> Prelude Data.Either> :t m<br>> m :: Maybe Integer<br><br>So to create a value of type (Maybe ...), you can use Just.<br><br>> Prelude Data.Either> let l = 2:[]<br>> Prelude Data.Either> :t l<br>> l :: [Integer]<br><br>So to create a value of type [...], you can use (:) and [].<br><br>> Prelude Data.Either> let g = getLine<br>> Prelude Data.Either> :t g<br>> g :: IO String<br><br>So to create a value of type (IO ...),
you can use getLine.<br><br>> Prelude Data.Either> let e = Right "abc"<br>> Prelude Data.Either> :t e<br>> e :: Either a [Char]<br><br>So to create a value of type (Either ... ...), you can use Right.<br><br>> How can I similarly create an instance of (->) [...] ?<br><br>An "instance of (->)" is usually called a function. And functions are created by lambda abstraction:<br><br> Prelude> let f = \x -> x<br> Prelude> :t f<br> f :: t -> t<br><br>So to create a value of type (... -> ...), you can use \.<br><br><br>Just like Either, -> is a binary type constructor. Just like (Either a b) is a type, (a -> b) is a type. And very much like you can create (Either a b) values with Left and Right, you can create (a -> b) values with \.<br><br> Tillmann<br><br>PS. After studying how to construct values, it may be instructive to study how to take them apart. For example, Bool values can be taken
apart by if-then-else expressions. What about Either, IO and -> values?<br></div></blockquote></td></tr></table><br>