Re: [Haskell-cafe] what is the status of haskell's mail libraries?
Sure -- I'll look at doing that. No time today but should be able to look at that on Friday. -Rob On Wed, Dec 29, 2010 at 6:02 AM, Michael Snoyman mich...@snoyman.com wrote: This looks very good, thank you! One comment: do you think it would be possible to add a function for sending a mime-mail Mail datatype directly? I see that you provide a wrapper around simpleMail in your sendMimeMail function, but that won't always be sufficient. Michael On Tue, Dec 28, 2010 at 9:46 PM, Robert Wills wrwi...@gmail.com wrote: I've finally gotten around to doing an update to HaskellNet which provides along with some cleanups integration with mime-mail. There is an example of its usage at: example/smtpMimeMail.hs in http://hackage.haskell.org/package/HaskellNet -Rob On Wed, Oct 27, 2010 at 11:05 AM, Michael Snoyman mich...@snoyman.com wrote: On Wed, Oct 27, 2010 at 10:39 AM, Henk-Jan van Tuyl hjgt...@chello.nl wrote: On Wed, 27 Oct 2010 04:46:07 +0200, Michael Snoyman mich...@snoyman.com wrote: I just release mime-mail[1], which can construct multipart messages. Note, that this will not run on Windows, as it gives command /usr/sbin/sendmail The sendmail feature will not work on Windows (and you're right, I should document that more clearly). However, rendering of email messages is completely cross-platform, and there was some talk of getting either HaskellNet or SMTPClient to work with mime-mail, which would allow direct sending of email via SMTP. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] The IO monad is 45 years old
The unabated debate about exactly how much category theory one needs to know to understand that strange beast of IO prompts a thought if monads, like related continuations, are the things that are destined to be rediscovered time and time again. An old (1994) paper on category theory monads and functional programming included an interesting historical side-note. It turns out that the RealWorld-passing trick underlying the implementation of the IO monad, the trick that made it possible to embed truly side-effecting operations into pure Haskell -- the trick is 45 years old. It has been first published in February 1965. That 1965 paper also anticipated State and Writer monad, call/cc, streams and delayed evaluations, relation of streams with co-routines, and even stream fusion. First, here is the historical aside, cited from Jonathan M. D. Hill and Keith Clarke An Introduction to Category Theory, Category Theory Monads, and Their Relationship to Functional Programming. 1994 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.6497 [blockquote] 3 An historical aside Monads are typically equated with single-threadedness, and are therefore used as a technique for incorporating imperative features into a purely functional language. Category theory monads have little to do with single-threadedness; it is the sequencing imposed by composition that ensures single-threadedness. In a Wadler-ised monad this is a consequence of bundling the Kleisli star and flipped compose into the bind operator. There is nothing new in this connection. Peter Landin in his Algol 60 used functional composition to model semi-colon. Semi-colon can be thought of as a state transforming operator that threads the state of the machine throughout a program. The work of Peyton-Jones and Wadler has turned full circle back to Landin's earlier work as their use of Moggi's sequencing monad enables real side-effects to be incorporated into monad operations such as print. This is similar to Landin's implementation of his sharing machine where the assignandhold function can side-effect the store of the sharing machine because of the sequencing imposed by functional composition. Landin defined that `Imperatives are treated as null-list producing functions' [In Landin's paper, () is the syntactic representation of the empty list and not the unit.]. The assignandhold imperative is subtly different in that it enables Algol's compound statements to be handled. The function takes a store location and a value as its argument, and performs the assignment to the store of the sharing machine, returning the value assigned as a result of the function. Because Landin assumed applicative order reduction, the K combinator was used to return (), and the imperative was evaluated as a side effect by the unused argument of the K-combinator. Statements are formed by wrapping such an imperative in a lambda expression that takes () as an argument. Two consecutive Algol-60 assignments would be encoded in the lambda calculus as: Algol 60 | Lambda Calculus x:= 2; | ( (\() - K () (assignandhold x 2)) . x:= -3; | (\() - K () (assignandhold x (-3))) ) () By using a lambda with () as its parameter, () can be thought of as the `state of the world' that is threaded throughout a program by functional composition. [/blockquote] Peter Landin's paper is remarkable indeed: P. J. Landin. A correspondence between ALGOL 60 and Church's lambda notation. Communications of the ACM, 8(2):89-101, February 1965. (Part 2 in CACM Vol 8(2) 1965, pages 158-165.) http://portal.acm.org/citation.cfm?id=363749 First the reader will notice the `where' notation. Peter Landin even anticipated the debate on `let' vs `where', saying ``The only consideration in choosing between `let' and `where' will be the relative convenience of writing an auxiliary definition before or after the expression it qualifies.'' The ()-passing trick is described in full on p100, with remarkable clarity: ``Statements. Each statement is rendered as a 0-list- transformer, i.e. a none-adic function producing the nullist for its result. It achieves by side-effects a transformation of the current state of evaluation. ... Compound statements are considered as functional products (which we indicate informally by infixed dots).'' A remark ``However, input/output devices can be modeled as named lists, with special, rather restricted functions associated. ... Writing is modeled by a procedure that, operates on a list, and appends a new final segment derived from other variables. (Alternatively, a purely functional approach can be contrived by including the transformed list among the results.)'' anticipated the State and Writer monads as well. Another remark, in the section on Streams, ``This correspondence [laws of head/tail/cons] serves two related purposes. It enables us to perform operations on lists (such as generating them,
Re: [Haskell-cafe] ghc +RTS -M and -A behaving strange
On Tuesday 28 December 2010 20:37:50, Johannes Waldmann wrote: Hello. When I run a program compiled with ghc-6.12.3 like this: ... +RTS -A2G -M8G -s I get as an answer: Heap exhausted; Current maximum heap size is 0 bytes (0 MB); use `+RTS -Msize' to increase it. Overflow, I'm almost sure. ghci (8*2^30) `mod` (2^32) 0 and when I put the options ... +RTS -A2000M -M8000M -s I get Heap exhausted; Current maximum heap size is 4093640704 bytes (3904 MB); use `+RTS -Msize' to increase it. ghci (8000*2^20) `mod` (2^32) 4093640704 Seems GHC uses Word for the allocation figures and you have a 32-bit system. and both numbers look strange. The behaviour of the program is also strange (instead of heap exhausted I'd expect it to do some smore garbage collections, which it does indeed without the -A option) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] multi type addition
On Tue, 28 Dec 2010, aditya siram wrote: The problem here is that unfortunately the Haskell type system cannot do coercion. I'd omit the unfortunately. For me it is a good thing that Haskell does not silently apply lossy number conversions, as e.g. MatLab does. 'realToFrac' allows conversion to Float. It requires 'Real' constraint. Your 'Num' constraint is too weak, since 'Complex' is also in 'Num' type class. http://www.haskell.org/haskellwiki/Converting_numbers http://www.haskell.org/haskellwiki/Generic_number_type ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell] haskell.org migration complete
On Sun, 5 Dec 2010, Henning Thielemann wrote: Thomas Schilling schrieb: I created http://www.haskell.org/haskellwiki/MigratingWikiContent to list known issues and workarounds. Please feel free to extend that page where needed. ... I did not like to add these items while having to log in over unsecure HTTP connection. Formerly I could just replace http: by https: which is no longer possible. Is there a Trac where we can watch the progress of the fixes? Is re-activating SSL support still on the ToDo list? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc +RTS -M and -A behaving strange
ghci (8000*2^20) `mod` (2^32) 4093640704 Seems GHC uses Word for the allocation figures Interesting. Then how can I set the memory bounds that I want? The machine has 12 GB, and if I leave out any RTS options, then the ghc-compiled program will happily consume it all. and you have a 32-bit system. uname -a Linux --- 2.6.32-bpo.5-amd64 #1 SMP Sat Sep 18 19:03:14 UTC 2010 x86_64 GNU/Linux cat /proc/cpuinfo processor : 0 .. 7 vendor_id : GenuineIntel cpu family : 6 model : 26 model name : Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz ghc --version The Glorious Glasgow Haskell Compilation System, version 6.12.3 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Incrementially updating an array
On Wed, 29 Dec 2010, Robert Clausecker wrote: Am Mittwoch, den 29.12.2010, 13:29 +0100 schrieb Henning Thielemann: I don't know, I hope it's doing its best. :-) You might compare speed of Array.accum with a manually written foldl with (//). At a glance onto it's sourcecode it actually does, but there are actually other problems now, as my program now runs out of stack space. (The list to accumulate contains about 100 elements). I guess it's all about that the garbage collector can't handle such things very well. The pure number of 100 elements should not be a problem. You may post the failing code. I guess it has something to do with: http://www.haskell.org/haskellwiki/Stack_overflow ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Reader monad
From: Control.Monad.Reader type Reader r = ReaderT r IdentityThe parameterizable reader monad. Computations are functions of a shared environment. The return function ignores the environment, while = passes the inherited environment to both subcomputations Is there an unparameterizable reader monad? Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
On Wed, Dec 29, 2010 at 8:06 AM, michael rice nowg...@yahoo.com wrote: Is there an unparameterizable reader monad? I'm not sure this is the answer you are looking for, but it seems like the obvious one. Pick an r, say String. Now Reader String is an unparameterizable reader monad that passes around a String. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
Hi, Ryan. Since I'm trying to understand Reader, I wanted to be aware of all cases of Reader. == From the docs (and tuts) newtype creates a new type out of an existing type and gives a single constructor for doing so. From: http://www.haskell.org/tutorial/moretypes.html newtype Natural = MakeNatural Integer This creates an entirely new type, Natural, whose only constructor contains a single Integer. The constructor MakeNatural converts between an Natural and an Integer: toNatural :: Integer - Natural toNatural x | x 0 = error Can't create negative naturals! | otherwise = MakeNatural x fromNatural :: Natural - Integer fromNatural (MakeNatural i) = i In the above case the existing type is Integer. The new type behaves like the existing type, but we can pattern match with the new type. ++ In the case of ReaderT and StateT newtype ReaderT r m a = ReaderT { -- | The underlying computation, as a function of the environment. runReaderT :: r - m a } newtype StateT s m a = StateT { runStateT :: s - m (a, s) } what is the existing type? Michael --- On Wed, 12/29/10, Ryan Ingram ryani.s...@gmail.com wrote: From: Ryan Ingram ryani.s...@gmail.com Subject: Re: [Haskell-cafe] Reader monad To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Wednesday, December 29, 2010, 11:11 AM On Wed, Dec 29, 2010 at 8:06 AM, michael rice nowg...@yahoo.com wrote: Is there an unparameterizable reader monad? I'm not sure this is the answer you are looking for, but it seems like the obvious one. Pick an r, say String. Now Reader String is an unparameterizable reader monad that passes around a String. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
On Wed, 29 Dec 2010, michael rice wrote: In the case of ReaderT and StateT newtype ReaderT r m a = ReaderT { -- | The underlying computation, as a function of the environment. runReaderT :: r - m a } newtype StateT s m a = StateT { runStateT :: s - m (a, s) } what is the existing type? The existing type is 'r - m a'. You could also write newtype ReaderT r m a = ReaderT (r - m a) This would be the same type as above, but it would have no accessor function 'runReaderT'. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
2010/12/29 michael rice nowg...@yahoo.com From the docs (and tuts) newtype creates a new type out of an existing type and gives a single constructor for doing so. what is the existing type? Michael, you may want to see this section: http://learnyouahaskell.com/functors-applicative-functors-and-monoids#the-newtype-keyword and also section titled type vs. newtype vs. data below. It has good explanation why there is at least three keywords in Haskell to define types, and which of them do what. And how they do it. From my experience, this book in a whole could be useful to you. It also has explanation how Reader is constructed step-by-step. As far as I know, there has been code for Reader monad in Haskell Wiki. Unfortunately, after it has been migrated, page not found error has become not very uncommon on it, and either i was not able to found it, or it really is missing. Out of practical considerations, library authors decided to define more complicated ReaderT monad transformer, because it can be made to behave as Reader if the former wraps Identity monad. Hope this helps. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
I think of (r - m a) as a type signature and Int or Bool by themselves as types. So, all type signatures are themselves types? Michael --- On Wed, 12/29/10, Henning Thielemann lemm...@henning-thielemann.de wrote: From: Henning Thielemann lemm...@henning-thielemann.de Subject: Re: [Haskell-cafe] Reader monad To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Wednesday, December 29, 2010, 12:28 PM On Wed, 29 Dec 2010, michael rice wrote: In the case of ReaderT and StateT newtype ReaderT r m a = ReaderT { -- | The underlying computation, as a function of the environment. runReaderT :: r - m a } newtype StateT s m a = StateT { runStateT :: s - m (a, s) } what is the existing type? The existing type is 'r - m a'. You could also write newtype ReaderT r m a = ReaderT (r - m a) This would be the same type as above, but it would have no accessor function 'runReaderT'. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
Hi, Michael Rice wrote: I think of (r - m a) as a type signature and Int or Bool by themselves as types. So, all type signatures are themselves types? Yes. In Haskell, functions are first class, so function types like (r - m a) are themselves types. Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
Hi, Michael. Yes, I'd already noticed that ReaderT preceded Reader. Guess I'll have to check out the Indentity monad too. I hope it's not dependent upon yet another monad. ;-) Thanks for the link. I go there a lot. Michael --- On Wed, 12/29/10, Michael Lazarev lazarev.mich...@gmail.com wrote: From: Michael Lazarev lazarev.mich...@gmail.com Subject: Re: [Haskell-cafe] Reader monad To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Wednesday, December 29, 2010, 12:42 PM 2010/12/29 michael rice nowg...@yahoo.com From the docs (and tuts) newtype creates a new type out of an existing type and gives a single constructor for doing so. what is the existing type? Michael, you may want to see this section: http://learnyouahaskell.com/functors-applicative-functors-and-monoids#the-newtype-keyword and also section titled type vs. newtype vs. data below. It has good explanation why there is at least three keywords in Haskell to define types, and which of them do what. And how they do it. From my experience, this book in a whole could be useful to you. It also has explanation how Reader is constructed step-by-step. As far as I know, there has been code for Reader monad in Haskell Wiki. Unfortunately, after it has been migrated, page not found error has become not very uncommon on it, and either i was not able to found it, or it really is missing. Out of practical considerations, library authors decided to define more complicated ReaderT monad transformer, because it can be made to behave as Reader if the former wraps Identity monad. Hope this helps. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc +RTS -M and -A behaving strange
On Wednesday 29 December 2010 15:41:22, Johannes Waldmann wrote: ghci (8000*2^20) `mod` (2^32) 4093640704 Seems GHC uses Word for the allocation figures Looking at the rts-code, maxHeapSize is in blocks (4096 bytes, as far as I can see) and the code for setting it uses double and StgWord64. Though the type of maxHeapSize is nat (unsigned int, which may be 32 bits even on 64-bit systems?), 8G are 2097152 blocks, so the number is well within range and no overflow should occur. But the `heap exhausted' message gives the heap size in bytes, with argument type lnat (unsigned long). So if sizeof(unsigned long) is 4 on your system, the heap exhausted message would print 0 bytes resp 4093640704 bytes even if the heap size is correctly set to 8G resp 8000M. Can you watch the allocation with top to see whether the programme consumes the 8G and just the reported figures are wrong? In any case, some bug report is in order, it only remains to find out whether just the reporting is off or also the allocation code. Interesting. Then how can I set the memory bounds that I want? Should work, as far as I can tell. The machine has 12 GB, and if I leave out any RTS options, then the ghc-compiled program will happily consume it all. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
On Wednesday 29 December 2010 19:30:11, michael rice wrote: Yes, I'd already noticed that ReaderT preceded Reader. Guess I'll have to check out the Indentity monad too. I hope it's not dependent upon yet another monad. No, the Identity monad stands alone. And as the name suggests, it's pretty simple. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
Hi, Daniel. I had an Aha! moment and it all makes sense now. Just as the State monad can hold a generator (which can change) and pass it down a calculation chain, a Reader monad can hold an environment (which doesn't change) and pass it down a calculation chain. I was wondering how I could include a (global) house betting limit in that craps application I've been playing with (without passing it as a parameter) and it sounds like the Reader monad would be an ideal candidate. Correct? It also sounds like a job for monad transforms. Michael --- On Wed, 12/29/10, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: From: Daniel Fischer daniel.is.fisc...@googlemail.com Subject: Re: [Haskell-cafe] Reader monad To: haskell-cafe@haskell.org Cc: michael rice nowg...@yahoo.com Date: Wednesday, December 29, 2010, 2:47 PM On Wednesday 29 December 2010 19:30:11, michael rice wrote: Yes, I'd already noticed that ReaderT preceded Reader. Guess I'll have to check out the Indentity monad too. I hope it's not dependent upon yet another monad. No, the Identity monad stands alone. And as the name suggests, it's pretty simple. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
On 10-12-29 12:50 PM, michael rice wrote: I think of (r - m a) as a type signature and Int or Bool by themselves as types. So, all type signatures are themselves types? http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-620004 In particular gendecl → vars :: [context =] type(type signature) Therefore I think of n :: Int f :: r - m a as type signatures, and their right-hand sides alone, Int r - m a as types. I also include the context = part in my types, for example m :: Num a = a I take the type to be Num a = a The grammar splits out the context = part just for the sake of reuse in other places such as topdecl → ... | data [context =] simpletype [= constrs] [deriving] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
2010/12/29 Albert Y. C. Lai tre...@vex.net On 10-12-29 12:50 PM, michael rice wrote: I think of (r - m a) as a type signature and Int or Bool by themselves as types. So, all type signatures are themselves types? http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-620004 In particular gendecl → vars :: [context =] type(type signature) Therefore I think of n :: Int f :: r - m a as type signatures, and their right-hand sides alone, Int r - m a as types. I used to think about types as mathematical sets, and type signatures in this case are just sequences of characters denoting these types. They of course must have some formal grammar as it was quoted above. I'd like to note that one type can be denoted by many type signatures. For example, String and [Char]. And as another case, a - b and c - d. One may come up with more advanced examples involving type families. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
2010/12/29 michael rice nowg...@yahoo.com I had an Aha! moment and it all makes sense now. Just as the State monad can hold a generator (which can change) and pass it down a calculation chain, a Reader monad can hold an environment (which doesn't change) and pass it down a calculation chain. I was wondering how I could include a (global) house betting limit in that craps application I've been playing with (without passing it as a parameter) and it sounds like the Reader monad would be an ideal candidate. Correct? It also sounds like a job for monad transforms. That is right. You need transformers if you want to have one value as settings to read, other value as a state, and so on, and they must be simultaneously accessible in some function. Or, for example, if you want to build a sequence of IO actions by functions that share the same environment. After you said that you had an Aha! moment, I remembered how I had something alike not very long ago. That was surprising event when I ended up with some transformer stack written myself although just several minutes ago I would consider this to be some dark wizardry. When I was dealing with monads for the first time, I tried reading source code and explanations. Soon I found that pure unapplied theory was making such a dismal, depressing feeling on me that I was not able to continue. But some time after I was writing an application in Haskell. It was real, and contrary to my previous theoretical studies the process was much fun. I had good FP background at that time, and had no problem writing everything in functional style. Since everything that can be done with monads can also be done without them, I didn't use any monad except IO (in main function :) ). Not that I especially avoided them, I just didn't think about them. And then I noticed that I constantly pass one same parameter to a lot of functions. And then -- since I remembered the boring theory -- bam! -- I introduced Reader into the code. And it worked. Which tempted me to interweave Reader and Writer, and so on, and twenty minutes later I had monstrosity that I only saw before in others' code: ReaderT WriterT State and so on :) So, good luck with your application! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] The IO monad is 45 years old
Indeed, one might think that there is very little new :) I also recommend the following handy book on functional programming (based on Landin's ideas among others ) by William H Burge called recursive Programming Techniques from 1975. http://www.amazon.com/gp/product/0201144506?SubscriptionId=0QCHRJVSKG6F3BRGBNG2tag=pbs_00017-20linkCode=xm2camp=2025creative=165953creativeASIN=0201144506 http://www.amazon.com/gp/product/0201144506?SubscriptionId=0QCHRJVSKG6F3BRGBNG2tag=pbs_00017-20linkCode=xm2camp=2025creative=165953creativeASIN=0201144506 On Wed, Dec 29, 2010 at 1:13 AM, o...@okmij.org wrote: The unabated debate about exactly how much category theory one needs to know to understand that strange beast of IO prompts a thought if monads, like related continuations, are the things that are destined to be rediscovered time and time again. An old (1994) paper on category theory monads and functional programming included an interesting historical side-note. It turns out that the RealWorld-passing trick underlying the implementation of the IO monad, the trick that made it possible to embed truly side-effecting operations into pure Haskell -- the trick is 45 years old. It has been first published in February 1965. That 1965 paper also anticipated State and Writer monad, call/cc, streams and delayed evaluations, relation of streams with co-routines, and even stream fusion. First, here is the historical aside, cited from Jonathan M. D. Hill and Keith Clarke An Introduction to Category Theory, Category Theory Monads, and Their Relationship to Functional Programming. 1994 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.53.6497 [blockquote] 3 An historical aside Monads are typically equated with single-threadedness, and are therefore used as a technique for incorporating imperative features into a purely functional language. Category theory monads have little to do with single-threadedness; it is the sequencing imposed by composition that ensures single-threadedness. In a Wadler-ised monad this is a consequence of bundling the Kleisli star and flipped compose into the bind operator. There is nothing new in this connection. Peter Landin in his Algol 60 used functional composition to model semi-colon. Semi-colon can be thought of as a state transforming operator that threads the state of the machine throughout a program. The work of Peyton-Jones and Wadler has turned full circle back to Landin's earlier work as their use of Moggi's sequencing monad enables real side-effects to be incorporated into monad operations such as print. This is similar to Landin's implementation of his sharing machine where the assignandhold function can side-effect the store of the sharing machine because of the sequencing imposed by functional composition. Landin defined that `Imperatives are treated as null-list producing functions' [In Landin's paper, () is the syntactic representation of the empty list and not the unit.]. The assignandhold imperative is subtly different in that it enables Algol's compound statements to be handled. The function takes a store location and a value as its argument, and performs the assignment to the store of the sharing machine, returning the value assigned as a result of the function. Because Landin assumed applicative order reduction, the K combinator was used to return (), and the imperative was evaluated as a side effect by the unused argument of the K-combinator. Statements are formed by wrapping such an imperative in a lambda expression that takes () as an argument. Two consecutive Algol-60 assignments would be encoded in the lambda calculus as: Algol 60 | Lambda Calculus x:= 2; | ( (\() - K () (assignandhold x 2)) . x:= -3; | (\() - K () (assignandhold x (-3))) ) () By using a lambda with () as its parameter, () can be thought of as the `state of the world' that is threaded throughout a program by functional composition. [/blockquote] Peter Landin's paper is remarkable indeed: P. J. Landin. A correspondence between ALGOL 60 and Church's lambda notation. Communications of the ACM, 8(2):89-101, February 1965. (Part 2 in CACM Vol 8(2) 1965, pages 158-165.) http://portal.acm.org/citation.cfm?id=363749 First the reader will notice the `where' notation. Peter Landin even anticipated the debate on `let' vs `where', saying ``The only consideration in choosing between `let' and `where' will be the relative convenience of writing an auxiliary definition before or after the expression it qualifies.'' The ()-passing trick is described in full on p100, with remarkable clarity: ``Statements. Each statement is rendered as a 0-list- transformer, i.e. a none-adic function producing the nullist for its result. It achieves by side-effects a transformation of the current state of evaluation. ... Compound statements are considered as functional products
Re: [Haskell-cafe] Reader monad
On Wed, Dec 29, 2010 at 1:48 PM, Michael Lazarev lazarev.mich...@gmail.comwrote: 2010/12/29 michael rice nowg...@yahoo.com I had an Aha! moment and it all makes sense now. Just as the State monad can hold a generator (which can change) and pass it down a calculation chain, a Reader monad can hold an environment (which doesn't change) and pass it down a calculation chain. I was wondering how I could include a (global) house betting limit in that craps application I've been playing with (without passing it as a parameter) and it sounds like the Reader monad would be an ideal candidate. Correct? It also sounds like a job for monad transforms. That is right. You need transformers if you want to have one value as settings to read, other value as a state, and so on, and they must be simultaneously accessible in some function. Or, for example, if you want to build a sequence of IO actions by functions that share the same environment. After you said that you had an Aha! moment, I remembered how I had something alike not very long ago. That was surprising event when I ended up with some transformer stack written myself although just several minutes ago I would consider this to be some dark wizardry. When I was dealing with monads for the first time, I tried reading source code and explanations. Soon I found that pure unapplied theory was making such a dismal, depressing feeling on me that I was not able to continue. But some time after I was writing an application in Haskell. It was real, and contrary to my previous theoretical studies the process was much fun. I had good FP background at that time, and had no problem writing everything in functional style. Since everything that can be done with monads can also be done without them, I didn't use any monad except IO (in main function :) ). Not that I especially avoided them, I just didn't think about them. And then I noticed that I constantly pass one same parameter to a lot of functions. And then -- since I remembered the boring theory -- bam! -- I introduced Reader into the code. And it worked. Which tempted me to interweave Reader and Writer, and so on, and twenty minutes later I had monstrosity that I only saw before in others' code: ReaderT WriterT State and so on :) Reader Writer State is commonly needed in big applications so transformers provides one for us: http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-Trans-RWS-Lazy.html Pretty cool stuff if you ask me. I often wondered about the correct stacking order of Monad transformers, or how often it mattered. Dave So, good luck with your application! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reader monad
2010/12/30 David Leimbach leim...@gmail.com: Reader Writer State is commonly needed in big applications so transformers provides one for us: http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-Trans-RWS-Lazy.html Pretty cool stuff if you ask me. I often wondered about the correct stacking order of Monad transformers, or how often it mattered. Thanks, it is very cool indeed! And it turns out that it's not simply kind of the type RWST r w s m a = ReaderT r WriterT w StateT s m a, it has completely independent implementation. It is done in one layer, so no lifts for tell, get, put, modify and so on. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Manatee-0.1.6 release!
Hi all, Manatee-0.1.6 release, sorry for late, I was tired of the many trivial this month. http://www.youtube.com/watch?v=weS6zys3U8k hackage.haskell.org/package/manatee New version Manatee support customize and hot-swap, like elisp for Emacs, but much much fast and safe. Please look http://www.flickr.com/photos/48809...@n02/5304662424/lightbox/ to understand hot-swap framework. Example, copy IrcClient.hs (https://patch-tag.com/r/AndyStewart/manatee-ircclient/snapshot/current/content/pretty/Config/ IrcClient.hs) to directory ~/.manatee/config/ then you can modify IrcClient.hs when manatee-ircclient is running, you just need press C-u to dynamic loading new version to *running* manatee-ircclient and won't lose state. Because GHC won't release memory after you dynamic-linking new version, so i recommend use this features as *develop mode* to accelerate develop. Once you adjust finish, you can press C-i to compile current configure file to build new manatee-ircclient. Next step, I will focus my time on IDE features Enjoy! -- Andy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] What are these comments for {-# SCC Mangler #-}
What are these comments for in Happy ? {-# SCC Mangler #-} Many thanks in advance, Aaron ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are these comments for {-# SCC Mangler #-}
Check out the Time Profiling of the Chapter 25 of Real World Haskell [1] for a detailed explanation. -deech [1] http://book.realworldhaskell.org/read/profiling-and-optimization.html On Wed, Dec 29, 2010 at 6:48 PM, Aaron Gray aaronngray.li...@gmail.com wrote: What are these comments for in Happy ? {-# SCC Mangler #-} Many thanks in advance, Aaron ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Lambda Calculus: Bound and Free formal definitions
Hi, Presently I am going through AJT Davie's text An Introduction to Functional Programming Systems Using Haskell. On page 84, regarding formal definitions of FREE and BOUND variables he gives Defn 5.2 as The variable X is free in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2 c) omitted Then in Defn 5.3 he states The variable X is bound in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2. c) omitted Now, are these definitions correct? They seem to contradict each otherand they don't make much sense on their own either (try every combination of E1 and E2 for bound and free and you'll see what I mean). If it is correct then please give some examples of E1 and E2 showing exactly why. Personally I think that there's an error in the book. You can see the full text on Google Books (page 84) Thanks for reading! Mark Spezzano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lambda Calculus: Bound and Free formal definitions
Was there a typo in your email? Because those two definitions appear identical. I could be missing something - I haven't read that book. Antoine On Wed, Dec 29, 2010 at 9:05 PM, Mark Spezzano mark.spezz...@chariot.net.au wrote: Hi, Presently I am going through AJT Davie's text An Introduction to Functional Programming Systems Using Haskell. On page 84, regarding formal definitions of FREE and BOUND variables he gives Defn 5.2 as The variable X is free in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2 c) omitted Then in Defn 5.3 he states The variable X is bound in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2. c) omitted Now, are these definitions correct? They seem to contradict each otherand they don't make much sense on their own either (try every combination of E1 and E2 for bound and free and you'll see what I mean). If it is correct then please give some examples of E1 and E2 showing exactly why. Personally I think that there's an error in the book. You can see the full text on Google Books (page 84) Thanks for reading! Mark Spezzano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Incorrectly inferring type [t]
Hi All, I've spent a lot of time trying to write a version of concat, which concatenates lists of any depth: So: concat'' [[[1,2],[3,4]],[[5]]] would return: [1,2,3,4,5] The code is: concat'' :: [a] - [b] concat'' ((y:ys):xs) = (concat'' (y:ys)) ++ (concat'' xs) concat'' [] = [] concat'' (x:xs) = (x:xs) And the inevitable error is: test.hs:298:12: Couldn't match expected type `a' against inferred type `[t]' `a' is a rigid type variable bound by the type signature for `concat''' at test.hs:297:13 In the pattern: y : ys In the pattern: (y : ys) : xs In the definition of `concat''': concat'' ((y : ys) : xs) = (concat'' (y : ys)) ++ (concat'' xs) test.hs:300:24: Couldn't match expected type `b' against inferred type `[t]' `b' is a rigid type variable bound by the type signature for `concat''' at test.hs:297:20 In the first argument of `(:)', namely `x' In the expression: (x : xs) In the definition of `concat''': concat'' (x : xs) = (x : xs) Failed, modules loaded: none. Any help or advice would be appreciated. Will ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] [Haskell-beginners] Tying the knot
On Wed, Dec 29, 2010 at 7:22 PM, aditya siram aditya.si...@gmail.com wrote: My brain turns into strange braid when I see this kind of thing. I don't quite understand it and I've never used it in real world code but I'll try and explain anyway. Caveat emptor. Once when I was parsing a group of source files into an AST, the source files included 'copy' directives that allowed pieces of syntax to be a clone of some other piece of syntax - even across source files. So I did the whole process of parsing in the Reader monad, which was parametrized over the result of parsing all of the files. When I hit a copy directive, I simply called 'ask' and looked up the element I wanted to copy. It doesn't allow for separate processing of source files, but I didn't really need it. Antoine First forget about 'labelLeaves' and think a function that only returned the leaf count: count :: Tree a - Int count tree = c where c = count' tree count' (Branch a b) = na+nb where na = count' a nb = count' b count' (Leaf _) = 1 count $ Branch (Leaf hello) (Leaf world) 2 Now look at 'n' and imagine it was a memory location. Mentally substitute some hex address (like 0x) if it makes it easier. Here's what the function looks like now: labelLeaves :: Tree a - Tree Int labelLeaves tree = tree' where (0x, tree') = label 0x tree -- n is both result and argument! label 0x (Branch a b) = (na+nb, Branch a' b') where (na,a') = label 0x a (nb,b') = label 0x b label 0x (Leaf _) = (1, Leaf 0x) So if labelLeaves is given (Branch (Leaf hello) (Leaf world)) as an argument, and we continue to think of 'n' as a memory location the function returns something like: (Branch (Leaf 0x) (Leaf 0x)) The part of the function where the leaves are counted up is exactly like my 'count' example above, but when the function is done instead of just returning it this line: (n,tree') = label n tree assigns the final count to 'n'. If 'n' is a memory location the final leaf count would be sitting in 0x. Subbing the value at that location into the result we get: (Branch (Leaf 2) (Leaf 2)) -deech On Wed, Dec 29, 2010 at 4:52 PM, Patrick LeBoutillier patrick.leboutill...@gmail.com wrote: Heinrich, A canonical example is the following solution to the problem of labeling all the leaves in a tree with the total leaf count: data Tree a = Branch (Tree a) (Tree a) | Leaf a labelLeaves :: Tree a - Tree Int labelLeaves tree = tree' where (n, tree') = label n tree -- n is both result and argument! label n (Branch a b) = (na+nb, Branch a' b') where (na,a') = label n a (nb,b') = label n b label n (Leaf _) = (1, Leaf n) This looks completely freaky to me... how does it work? Is it the laziness that allows the sum to be calculated first while preserving the structure (as thunks?), and then once the value of n is known it is propagated back down the tree and the actual tree values constructed? Anyways this is really amazing to my newbie eyes... Patrick -- = Patrick LeBoutillier Rosemère, Québec, Canada ___ Beginners mailing list beginn...@haskell.org http://www.haskell.org/mailman/listinfo/beginners ___ Beginners mailing list beginn...@haskell.org http://www.haskell.org/mailman/listinfo/beginners ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How to make such code?
Hi, In Haskell's way, normally, we write: if condition then expression_true else expression_false But I just heard that, in fancy way, we could do: do ifNeedToDo doIt bluh May I have any clue here? -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Incorrectly inferring type [t]
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/29/10 22:05 , william murphy wrote: I've spent a lot of time trying to write a version of concat, which concatenates lists of any depth: So: concat'' [[[1,2],[3,4]],[[5]]] would return: [1,2,3,4,5] You can't do that, at least with a normal type signature. There might be some evil that can do it, but (as you found) if you try to do it naively you will get an error which amounts to this type can't represent both an item and a list of that item at the same time. - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk0b+Z0ACgkQIn7hlCsL25WFCQCeNkSf0+1pyJI+rpBWtk3uBsv5 qosAoIRQQyg78IPlHuQiiVleqmYUdQD+ =lOjO -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lambda Calculus: Bound and Free formal definitions
Duh, Sorry. Yes, there was a typo the second one should read If E is a combination E1 E2 then X is bound in E if and only if X is bound in E1 or is bound in E2. Apologies for that oversight! Mark On 30/12/2010, at 1:21 PM, Antoine Latter wrote: Was there a typo in your email? Because those two definitions appear identical. I could be missing something - I haven't read that book. Antoine On Wed, Dec 29, 2010 at 9:05 PM, Mark Spezzano mark.spezz...@chariot.net.au wrote: Hi, Presently I am going through AJT Davie's text An Introduction to Functional Programming Systems Using Haskell. On page 84, regarding formal definitions of FREE and BOUND variables he gives Defn 5.2 as The variable X is free in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2 c) omitted Then in Defn 5.3 he states The variable X is bound in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2. c) omitted Now, are these definitions correct? They seem to contradict each otherand they don't make much sense on their own either (try every combination of E1 and E2 for bound and free and you'll see what I mean). If it is correct then please give some examples of E1 and E2 showing exactly why. Personally I think that there's an error in the book. You can see the full text on Google Books (page 84) Thanks for reading! Mark Spezzano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lambda Calculus: Bound and Free formal definitions
On Wed, Dec 29, 2010 at 9:22 PM, Mark Spezzano mark.spezz...@chariot.net.au wrote: Duh, Sorry. Yes, there was a typo the second one should read If E is a combination E1 E2 then X is bound in E if and only if X is bound in E1 or is bound in E2. Seems odd. I recommend you always work from at least three different texts. Here's Hindley and Seldinhttp://www.amazon.com/Lambda-Calculus-Combinators-Introduction-Roger-Hindley/dp/0521898854/ref=dp_ob_title_bk : An occurrence of a variable x in a term P is called - *bound* if it is in the scope of a \x in P (NB: using \ as lambda) - *bound and binding* iff it is the x in \x - *free* otherwise The tricky question is: bound to what, exactly? -Gregg ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to make such code?
Hi, You're looking for 'when' as in: do condition - something when condition $ other things more things http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:when It is quite handy. Take care, Antoine On Wed, Dec 29, 2010 at 10:14 PM, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: Hi, In Haskell's way, normally, we write: if condition then expression_true else expression_false But I just heard that, in fancy way, we could do: do ifNeedToDo doIt bluh May I have any clue here? -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lambda Calculus: Bound and Free formal definitions
Hi all, Thanks for your comments Maybe I should clarify... For example, 5.2 FREE: If E1 = \y.xy then x is free If E2 = \z.z then x is not even mentioned So E = E1 E2 = x (\z.z) and x is free as expected So E = E2 E1 = \y.xy and x is free as expected 5.3 BOUND: = If E1 = \x.xy then x is bound If E2 = \z.z then is not even mentioned So E = E1 E2 = (\x.xy)(\z.z) = (\z.z)y -- Error: x is not bound but should be by the rule of 5.3 So E = E2 E1 = (\z.z)(\x.xy) = (\x.xy) then x is bound. Where's my mistake in the second-to-last example? Shouldn't x be bound (somewhere/somehow)? Thanks, Mark On 30/12/2010, at 1:52 PM, Mark Spezzano wrote: Duh, Sorry. Yes, there was a typo the second one should read If E is a combination E1 E2 then X is bound in E if and only if X is bound in E1 or is bound in E2. Apologies for that oversight! Mark On 30/12/2010, at 1:21 PM, Antoine Latter wrote: Was there a typo in your email? Because those two definitions appear identical. I could be missing something - I haven't read that book. Antoine On Wed, Dec 29, 2010 at 9:05 PM, Mark Spezzano mark.spezz...@chariot.net.au wrote: Hi, Presently I am going through AJT Davie's text An Introduction to Functional Programming Systems Using Haskell. On page 84, regarding formal definitions of FREE and BOUND variables he gives Defn 5.2 as The variable X is free in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2 c) omitted Then in Defn 5.3 he states The variable X is bound in the expression E in the following cases a) omitted b) If E is a combination E1 E2 then X is free in E if and only if X is free in E1 or X is free in E2. c) omitted Now, are these definitions correct? They seem to contradict each otherand they don't make much sense on their own either (try every combination of E1 and E2 for bound and free and you'll see what I mean). If it is correct then please give some examples of E1 and E2 showing exactly why. Personally I think that there's an error in the book. You can see the full text on Google Books (page 84) Thanks for reading! Mark Spezzano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] what is the status of haskell's mail libraries?
Note, that this will not run on Windows, as it gives command /usr/sbin/sendmail It sounds like mime-mail may be getting native support soon, but until then you may try what I've had success with on Windows. Grab a sendmail replacement like the one at http://glob.com.au/sendmail/. It's just a sendmail.exe executable that you can place in your path along with a .ini configuration file to go with it. -- Michael Steele -- -- Michael Steele ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Incorrectly inferring type [t]
First, what type would such a function have? Certainly not [a]-[b], because that type say that it can take a list of any type and turn it into a list of any other type, e.g., [Int]-[Bool]. On Thu, Dec 30, 2010 at 4:05 AM, william murphy will.t.mur...@gmail.comwrote: Hi All, I've spent a lot of time trying to write a version of concat, which concatenates lists of any depth: So: concat'' [[[1,2],[3,4]],[[5]]] would return: [1,2,3,4,5] The code is: concat'' :: [a] - [b] concat'' ((y:ys):xs) = (concat'' (y:ys)) ++ (concat'' xs) concat'' [] = [] concat'' (x:xs) = (x:xs) And the inevitable error is: test.hs:298:12: Couldn't match expected type `a' against inferred type `[t]' `a' is a rigid type variable bound by the type signature for `concat''' at test.hs:297:13 In the pattern: y : ys In the pattern: (y : ys) : xs In the definition of `concat''': concat'' ((y : ys) : xs) = (concat'' (y : ys)) ++ (concat'' xs) test.hs:300:24: Couldn't match expected type `b' against inferred type `[t]' `b' is a rigid type variable bound by the type signature for `concat''' at test.hs:297:20 In the first argument of `(:)', namely `x' In the expression: (x : xs) In the definition of `concat''': concat'' (x : xs) = (x : xs) Failed, modules loaded: none. Any help or advice would be appreciated. Will ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ; in do
Why do people put ; in do {}, or , in data fields, at the beginning of the line? -- Daryoush Weblog: http://onfp.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] SampleVar semantics, documentation vs. source
Hi, doc: http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.0.0/Control-Concurrent-SampleVar.html source: http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.0.0/src/Control-Concurrent-SampleVar.html The documentation for Control.Concurrent.SampleVar implies that a SampleVar is either filled or empty. The source code suggests that there are three possible states: full (when readers == 1), empty (when readers == 0), and empty with blocked readers (when readers 0). In particular, the isEmptySampleVar function, isEmptySampleVar :: SampleVar a - IO Bool isEmptySampleVar (SampleVar svar) = do (readers, _) - readMVar svar return (readers == 0) returns false in the third state, when readers 0. Can someone clarify the semantics of SampleVar? Thanks, Eric ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ; in do
I started for cleaner diffs and easier editing - I can add/remove a line at the end without editing any other line. Eventually I grew to like the look of it. Both styles are common, from what I can tell. Antoine On Wed, Dec 29, 2010 at 11:40 PM, Daryoush Mehrtash dmehrt...@gmail.com wrote: Why do people put ; in do {}, or , in data fields, at the beginning of the line? -- Daryoush Weblog: http://onfp.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Typeable TypeRep Ord instance.
On 01:08 Sun 05 Dec , Serguey Zefirov wrote: Why TypeRep does have equality and doesn't have ordering? It would be good to have that. I think the problem is, that it's hard to give an ordering that stays the same for all runs of your program. If you don't need this property you could use typeRepKey to give an instance as follows: instance Ord TypeRep where compare t1 t2 = compare (unsafePerformIO (typeRepKey t1)) (unsafePerformIO (typeRepKey t2)) I know it's not good style to use unsafePerformIO, but if you look at how typeRepKey is implemented I think it should be okay: typeRepKey :: TypeRep - IO Int typeRepKey (TypeRep (Key i) _ _) = return i (The Eq instance also uses the key for comparison.) Right now when I have to order two type representations I convert them to string and then compare. This is somewhat inefficient and not quite straightforward. The implementation above should be efficient but should not be used when data between multiple runs since the ordering may change. Andreas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] V.I.P.s and the associativity of merge'
Ok, after mulling over the issues that Will Ness has brought up in the last few days [1], I think I have a partial explanation for the apparent tension between Will's observations and Heinrich Apfelmus's Implicit Heaps article [2], which both concern the implementation of mergeAll [3]. The merge' function takes two ordered lists, with the head of the first list less than the head of the second, and merges their contents: merge' [] ys = ys merge' (x:xs) ys = x : merge xs ys The nice thing about this function is we can merge an infinite number of lists by folding right, if assume that the heads of those lists are appropriately ordered. This appears in Richard Bird's code at the end of Melissa O'Neill's Genuine Sieve of Eratosthenes, though undoubtedly this observation has been independently made by many people. Now, in an ordinary sense, merge' *is* an associative operator, in that given three fully defined ordered lists with ordered heads, merge' xs (merge' ys zs) == merge' (merge' xs ys) zs. This allows us to merge an infinite number of lists using an arbitrary tree of merge' operations, without ever worrying that we will return an incorrect result. (However, we might get stuck in a non-productive loop, for example if we fold left over an infinite list of ordered lists) However, Heinrich's article uses a stronger sense of associativity which includes laziness properties and thus captures some operational characteristics. In this sense, merge' *is not* associative.To remedy this, Heinrich uses VIPs to strengthen the associativity property of merge'. This raises the question, is there some combination of the shape of the merge' tree and some input for which using VIPs dramatically changes the efficiency of a mergeAll operation? I suspect the answer is yes, though I don't know for sure at this point in time. However, I do tacitly believe that the current tree that mergeAll uses doesn't exhibit this property for any input, and so I have simplified the implementations of mergeAll and unionAll in the latest version of data-ordlist-0.4.4 by avoiding the use of VIPs. This has the nice side benefit of modestly improving performance when the elements of the result are highly biased towards the first list. Best, Leon [1] http://permalink.gmane.org/gmane.comp.lang.haskell.cafe/84666 [2] http://apfelmus.nfshost.com/articles/implicit-heaps.html [3] http://hackage.haskell.org/packages/archive/data-ordlist/0.4.4/doc/html/Data-List-Ordered.html#v:mergeAll ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Lambda Calculus: Bound and Free formal definitions
Mark, Whether a variable is bound or free depends on the scope under consideration. In (\x. x) (\y. x) the variable x is bound in \x. x, but free in \y. x; hence, it's free in (\x. x) (\y. x) as a whole. However, in \x. (\x. x) (\y. x) it's bound... HTH, Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe