Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Re: function parameter types after flip (Daniel Fischer) 2. Re: some terminology (Maur??cio CA) 3. Re: Closure (Daniel Bastos) 4. monad transformers (Michael P Mossey) 5. Constructors as functions (was monad transformers) (Michael P Mossey) 6. Re: monad transformers (Brandon S. Allbery KF8NH) 7. Re: Constructors as functions (was monad transformers) (Isaac Dupree) 8. Re: Closure (Heinrich Apfelmus) 9. Circular programming (Maciej Piechotka) 10. Re: Circular programming (Peter Verswyvelen) ---------------------------------------------------------------------- Message: 1 Date: Thu, 13 Aug 2009 17:52:58 +0200 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] function parameter types after flip To: beginners@haskell.org Message-ID: <200908131752.58655.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" Am Donnerstag 13 August 2009 17:25:07 schrieb Robert Ziemba: > Can anyone help me understand the behavior of the following > expressions in ghci? I was trying to construct a flipped function > 'elem' that would accept a list of characters first but I ran into > this problem with the type signature. Thank you. > > Prelude Data.List Data.Char> :t elem > elem :: (Eq a) => a -> [a] -> Bool -- OK > Prelude Data.List Data.Char> :t (flip elem) > (flip elem) :: (Eq a) => [a] -> a -> Bool -- OK this is what I want > Prelude Data.List Data.Char> let fElem = (flip elem) > Prelude Data.List Data.Char> :t fElem > fElem :: [()] -> () -> Bool -- ?? Function > will not accept a [Char] It's the monomorphism restriction. If you bind a name by a simple pattern binding (like [let] fElem = flip elem) and don't give a type signature, it must have a monomorphic type and in ghci, that defaults to () for unconstrained type variables. Ways to fix the behaviour: 1. give an explicit type signature (good in code files anyway, but cumbersome at the ghci prompt) 2. make it a function binding: let fElem xs x = x `elem` xs let fElem xs = (`elem` xs) let fElem xs = flip elem xs 3. run ghci without the monomorphism restriction Prelude> :set -XNoMonomorphismRestriction Prelude> let fElem = flip elem Prelude> :t fElem fElem :: (Eq a) => [a] -> a -> Bool (that would be a good entry in your .ghci file anyway, you rarely want it unless you are a compiler writer) ------------------------------ Message: 2 Date: Thu, 13 Aug 2009 14:34:12 -0300 From: Maur??cio CA <mauricio.antu...@gmail.com> Subject: [Haskell-beginners] Re: some terminology To: beginners@haskell.org Message-ID: <h61iqk$cq...@ger.gmane.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed > I was looking at some code, saw a variable x, and said to myself, "Ah > that variable is a monad." Then I realized "Monad" is the name of a type > class. So maybe x should be called "an instance of a Monad." I think the > word "instance" in this case is OO-like; but in Haskell "instance" > refers to a type that is an instance of a type class. [...] In general, it helps to know that the current "de facto" Haskell standard actually accepts classes and instances built on top of many types: class SomeClass a b c where someF :: a -> b -> c anotherF :: b -> c -> a instance SomeClass T1 T2 T3 where someF = ... anotherF = ... This way it becomes clear that saying that some type "is of" or "instantiate" some class isn't apropriate. Best, Maurício ------------------------------ Message: 3 Date: Fri, 14 Aug 2009 23:46:02 +0000 (UTC) From: Daniel Bastos <dbasto...@toledo.com> Subject: [Haskell-beginners] Re: Closure To: beginners@haskell.org Message-ID: <h64svq$ck...@ger.gmane.org> In article <h5tjgk$6d...@ger.gmane.org>, Daniel Bastos wrote: > In article <20090729202442.ga8...@seas.upenn.edu>, > Brent Yorgey wrote: > >> With that said, on some level the idea of a closure is really just an >> implementation detail---I wouldn't say that understanding it is of >> fundamental importance in learning Haskell. But learning things never >> hurts (except when it does). > > So it sounds correct to say that a closure is a function that brings > an environment with it, such as variables defined outside of it. > > With this ability, we can construct functions on the fly because a > function can return a closure which is amended and, say, returned > again another closure more fully specified. Hello. This was actually a request for comments. Though I didn't say it. Does that sound correct? Any comments? Thanks much. ------------------------------ Message: 4 Date: Fri, 14 Aug 2009 17:55:02 -0700 From: Michael P Mossey <m...@alumni.caltech.edu> Subject: [Haskell-beginners] monad transformers To: beginners <beginners@haskell.org> Message-ID: <4a860766.7020...@alumni.caltech.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed In Martin Grabmuller's tutorial "Monad Transformers Step by Step", found here http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf he gives an example of composing ErrorT, StateT, ReaderT, and WriterT. Early in the paper, where he composes just ErrorT and ReaderT type Eval3 a = ReaderT Env (ErrorT String Identity) a he uses 'ask' and 'throwError' in some example code. I notice that he doesn't have to lift throwError into the ErrorT monad. Why is this? Do I misunderstand something about monad transformers? Is it a convenience definition of throwError? Same thing the rest of the paper. I don't see anywhere he lifts anything. Thanks, Mike ------------------------------ Message: 5 Date: Fri, 14 Aug 2009 18:03:59 -0700 From: Michael P Mossey <m...@alumni.caltech.edu> Subject: [Haskell-beginners] Constructors as functions (was monad transformers) To: beginners <beginners@haskell.org> Message-ID: <4a86097f.5030...@alumni.caltech.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Michael P Mossey wrote: > In Martin Grabmuller's tutorial "Monad Transformers Step by Step", found > here > > http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf > Additional question: in this paper he uses a data constructor in an interesting way: back-quoting it to make it an operator. I thought, "Huh, a constructor is a lot like a function?" I did some experiments and found that I can map a constructor over a list and I can compose a constructor with other functions. Cool. So is a constructor a function, in every sense? Thanks, Mike ------------------------------ Message: 6 Date: Fri, 14 Aug 2009 21:05:14 -0400 From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu> Subject: Re: [Haskell-beginners] monad transformers To: Michael P Mossey <m...@alumni.caltech.edu> Cc: beginners <beginners@haskell.org> Message-ID: <7766b05e-bba2-4f4d-894f-cd1d80cdd...@ece.cmu.edu> Content-Type: text/plain; charset="us-ascii" On Aug 14, 2009, at 20:55 , Michael P Mossey wrote: > In Martin Grabmuller's tutorial "Monad Transformers Step by Step", > found here > > http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf > > he gives an example of composing ErrorT, StateT, ReaderT, and > WriterT. Early in the paper, where he composes just ErrorT and ReaderT > > type Eval3 a = ReaderT Env (ErrorT String Identity) a > > he uses 'ask' and 'throwError' in some example code. I notice that > he doesn't have to lift throwError into the ErrorT monad. Why is > this? Do I misunderstand something about monad transformers? Is it a > convenience definition of throwError? Look for definitions of the form > instance MonadReader Eval3 where ... > instance MonadError Eval3 where ... These effectively "import" definitions of ask, throwError, etc. with implicit lifting. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20090814/9417d865/PGP-0001.bin ------------------------------ Message: 7 Date: Fri, 14 Aug 2009 21:10:40 -0400 From: Isaac Dupree <m...@isaac.cedarswampstudios.org> Subject: Re: [Haskell-beginners] Constructors as functions (was monad transformers) To: Michael P Mossey <m...@alumni.caltech.edu> Cc: beginners <beginners@haskell.org> Message-ID: <4a860b10.9070...@isaac.cedarswampstudios.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Michael P Mossey wrote: > Michael P Mossey wrote: >> In Martin Grabmuller's tutorial "Monad Transformers Step by Step", >> found here >> >> http://user.cs.tu-berlin.de/~magr/pub/Transformers.pdf >> > > Additional question: in this paper he uses a data constructor in an > interesting way: back-quoting it to make it an operator. I thought, > "Huh, a constructor is a lot like a function?" I did some experiments > and found that I can map a constructor over a list and I can compose a > constructor with other functions. Cool. So is a constructor a function, > in every sense? Yes. In expressions, a constructor is a function, no more and no less (albeit with some weird capitalization). Constructors however, can *also* be used in pattern-matching, unlike functions. That's the (only?) special thing about them. -Isaac ------------------------------ Message: 8 Date: Sat, 15 Aug 2009 09:44:16 +0200 From: Heinrich Apfelmus <apfel...@quantentunnel.de> Subject: [Haskell-beginners] Re: Closure To: beginners@haskell.org Message-ID: <h65p0h$rj...@ger.gmane.org> Content-Type: text/plain; charset=ISO-8859-15 Daniel Bastos wrote: > >> So it sounds correct to say that a closure is a function that brings >> an environment with it, such as variables defined outside of it. >> >> With this ability, we can construct functions on the fly because a >> function can return a closure which is amended and, say, returned >> again another closure more fully specified. > > Hello. This was actually a request for comments. Though I didn't say > it. Does that sound correct? Any comments? Thanks much. Yes, that's pretty much correct. The simplest example of a closure is indeed foo = add 3 where add = \x y -> x + y Reduction to weak head normal form yields foo = let x = 3 in \y -> x + y which means that foo is a function \y -> x + y paired with the value of the free variable x . Note that closures are an implementation detail. From a semantic point of view, add 3 can readily be understood as an ordinary function. Regards, apfelmus -- http://apfelmus.nfshost.com ------------------------------ Message: 9 Date: Sat, 15 Aug 2009 09:16:06 +0000 (UTC) From: Maciej Piechotka <uzytkown...@gmail.com> Subject: [Haskell-beginners] Circular programming To: beginners@haskell.org Message-ID: <loom.20090815t091033-...@post.gmane.org> Content-Type: text/plain; charset=us-ascii I'm not understending circular programming. What it is used for? Where feedback variable came from (yes - I know it's wrong question as Haskell is lazy)? I've read http://www.haskell.org/haskellwiki/Circular_programming but I didn't understend the concept and pattern. Regards ------------------------------ Message: 10 Date: Sat, 15 Aug 2009 13:43:16 +0200 From: Peter Verswyvelen <bugf...@gmail.com> Subject: Re: [Haskell-beginners] Circular programming To: Maciej Piechotka <uzytkown...@gmail.com> Cc: beginners@haskell.org Message-ID: <a88790d10908150443x470f0a51yd61a817efa54e...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" It might help to read the Yampa Arcade<http://haskell.cs.yale.edu/yale/papers/haskell-workshop03/yampa-arcade.pdf>and then Plugging a Space Leak with an Arrow<http://cs-www.cs.yale.edu/homes/hl293/download/leak.pdf>to get a practical example of circuit and circular programming. On Sat, Aug 15, 2009 at 11:16 AM, Maciej Piechotka <uzytkown...@gmail.com>wrote: > I'm not understending circular programming. What it is used for? > Where feedback variable came from (yes - I know it's wrong question as > Haskell > is lazy)? > > I've read http://www.haskell.org/haskellwiki/Circular_programming but I > didn't > understend the concept and pattern. > > Regards > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090815/d8755cf3/attachment.html ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 14, Issue 8 ****************************************