Re: [Haskell-cafe] Pattern matching does not work like this?
On Jul 15, 2009, at 2:30 PM, Hans Aberg wrote: If ++ could be pattern matched, what should have been the result of let (x++y)=[1,2,3] in (x,y)? It will branch. In terms of unification, you get a list of substitutions. f :: [a] - ([a],[a]) f (x ++ y) = (x,y) For an argument s, any pair (x, y) satisfying s = x ++ y will match. That is, if s = [s_1, ..., s_k], the solutions j = 0, ..., k, x = [s_1, ..., s_j], y = [s_(j+1), ..., s_k]. And for each one, a potentially different value could given. That is, s could produce multiple values. Curry (a Haskell extension with non-determinism) supports exactly that. Sergio Antoy and Michael Hanus: Declarative Programming with Function Patterns available at: http://www.informatik.uni-kiel.de/~mh/papers/ LOPSTR05.pdf -- Underestimating the novelty of the future is a time-honored tradition. (D.G.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] laziness blowup exercise
On Wed, Jul 15, 2009 at 6:35 PM, Ryan Ingramryani.s...@gmail.com wrote: iterate' f x = x `seq` x : iterate' f (f x) seems better; it doesn't evaluate list elements you don't visit. iterate'' f x = x : (iterate'' f $! f x) ...seems the most lazy strict iterate. (Bas wishes for a type system that can express the different strictness properties of these functions...) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Debugging methods for haskell
Fernan Bolando fernanbola...@mailc.net writes: Hi all I recently used 2 hours of work looking for a bug that was causing Program error: Prelude.!!: index too large This is not very informative. It did not give me a hint which function was causing this. In C adding a few printf would have helped me, but in haskell I was not sure how to do that. Can anybody point me to some debuggin method everyone uses. After 2 hours I did find the bug eventually. The code can be viewed here. Maybe some reformatting of the code would make finding bugs easier? http://plan9.bell-labs.com/sources/contrib/fernan/escomma/ I wonder if your code has to use !! at all? I took a look at a random module from the above link, and (without making much attempt at understanding it), I'd guess that using accumArray and friends would be more appropriate. Mostly you don't want to be doing indexing on lists. -- Jón Fairbairn jon.fairba...@cl.cam.ac.uk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
2009/7/16 Marc Weber marco-owe...@gmx.de I recall there was another method. Yeah, I even found it (using ghci and set -fbreak-on-exception) http://donsbot.wordpress.com/2007/11/14/no-more-exceptions-debugging-haskell-code-with-ghci/ Careful, better use -fbreak-on-error rather than -fbreak-on-exception. Some functions, e.g. 'doesFileExist', use exceptions internally and you might end up stopping at an exception that is benign. (Identifying the exception has become a little harder since we got extensible exceptions.) -- Push the envelope. Watch it bend. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
By the way, does Hat - the Haskell Tracer? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
By the way, does Hat - the Haskell Tracer? Please append: still work. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Debugging methods for haskell
On Thu, Jul 16, 2009 at 4:10 PM, Jon Fairbairnjon.fairba...@cl.cam.ac.uk wrote: I wonder if your code has to use !! at all? I took a look at a random module from the above link, and (without making much attempt at understanding it), I'd guess that using accumArray and friends would be more appropriate. Mostly you don't want to be doing indexing on lists. -- Jón Fairbairn jon.fairba...@cl.cam.ac.uk Thanks for everyone's suggestion. Don Stewarts tools seems to be most appropriate for me. Most of the !! are used to access a list of parameters similar to accessing structures in C. I am not particularly sure how to apply accumArray for something like that? I will go through the accumArray documentation and see how I might apply them. thanks again. fernan -- http://www.fernski.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Zippers on Wikibooks: teasing! :)
Peter Verswyvelen wrote: After my colleague explained me about zippers and how one could derive the datatype using differential rules, I had to read about it. So I started reading http://en.wikibooks.org/wiki/Haskell/Zippers#Mechanical_Differentiation This page contains the sentence: *For a systematic construction, we need to calculate with types. The basics of structural calculations with types are outlined in a separate chapter **Generic Programming*http://en.wikibooks.org/w/index.php?title=Haskell/Generic_Programmingaction=editredlink=1 * and we will heavily rely on this material* * * However, the generic programming link does not exist yet :-) A clear case of laziness on the author's part... wait, that would be me. :-O In any case, contributions to the wikibook would be most welcome. ;-) For now, I'd recommend Generic Programming: An introduction http://www.cse.chalmers.se/~patrikj/poly/afp98/ It's a bit verbose at times, but you only need the first few chapters to get an idea about polynomial functors (sums and pairs) and mu . Regards, apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] IFL 2009: Third Call for Papers
Call for Papers IFL 2009 Seton Hall University SOUTH ORANGE, NJ, USA http://tltc.shu.edu/blogs/projects/IFL2009/ * NEW * Registration is now opened! Register at: http://tltc.shu.edu/blogs/projects/IFL2009/registration.html Invited Speaker: Benjamin C. Pierce University of Pennsylvania Talk Title: How To Build Your Own Bidirectional Programming Language Registration Fee: Students: US$325.00 Non-students: US$375.00 * The 21st International Symposium on Implementation and Application of Functional Languages, IFL 2009, will be held for the first time in the USA. The hosting institution is Seton Hall University in South Orange, NJ, USA and the symposium dates are September 23-25, 2009. It is our goal to make IFL a regular event held in the USA and in Europe. The goal of the IFL symposia is to bring together researchers actively engaged in the implementation and application of functional and function-based programming languages. IFL 2009 will be a venue for researchers to present and discuss new ideas and concepts, work in progress, and publication-ripe results related to the implementation and application of functional languages and function-based programming. Following the IFL tradition, IFL 2009 will use a post-symposium review process to produce a formal proceedings which will be published by Springer in the Lecture Notes in Computer Science series. All participants in IFL 2009 are invited to submit either a draft paper or an extended abstract describing work to be presented at the symposium. These submissions will be screened by the program committee chair to make sure they are within the scope of IFL and will appear in the draft proceedings distributed at the symposium. Submissions appearing in the draft proceedings are not peer-reviewed publications. After the symposium, authors will be given the opportunity to incorporate the feedback from discussions at the symposium and will be invited to submit a revised full arcticle for the formal review process. These revised submissions will be reviewed by the program committee using prevailing academic standards to select the best articles that will appear in the formal proceedings. TOPICS IFL welcomes submissions describing practical and theoretical work as well as submissions describing applications and tools. If you are not sure if your work is appropriate for IFL 2009, please contact the PC chair at ifl2...@shu.edu. Topics of interest include, but are not limited to: language concepts type checking contracts compilation techniques staged compilation runtime function specialization runtime code generation partial evaluation (abstract) interpretation generic programming techniques automatic program generation array processing concurrent/parallel programming concurrent/parallel program execution functional programming and embedded systems functional programming and web applications functional programming and security novel memory management techniques runtime profiling and performance measurements debugging and tracing virtual/abstract machine architectures validation and verification of functional programs tools and programming techniques FP in Education PAPER SUBMISSIONS Prospective authors are encouraged to submit papers or extended abstracts to be published in the draft proceedings and to present them at the symposium. All contributions must be written in English, conform to the Springer-Verlag LNCS series format and not exceed 16 pages. The draft proceedings will appear as a technical report of the Department of Mathematics and Computer Science of Seton Hall University. IMPORTANT DATES Registration deadline August 15, 2009 Presentation submission deadline August 15, 2009 IFL 2009 Symposium September 23-25, 2009 Submission for review process deadline November 1, 2009 Notification Accept/Reject December 22, 2009 Camera ready version February 1, 2010 PROGRAM COMMITTEE Peter Achten University of Nijmegen, The Netherlands Jost Berthold Philipps-Universität Marburg, Germany Andrew Butterfield University of Dublin, Ireland Robby Findler Northwestern University, USA Kathleen Fisher ATT Research, USA Cormac Flanagan University of California at Santa Cruz, USA Matthew Flatt University of Utah, USA Matthew Fluet Rochester Institute of Technology, USA Daniel Friedman Indiana University, USA Andy Gill University of Kansas, USA Clemens Grelck University of Amsterdam/Hertfordshire, The Netherlands/UK Jurriaan Hage Utrecht University, The Netherlands Ralf Hinze Oxford University, UK Paul Hudak Yale University, USA John Hughes Chalmers University of Technology, Sweden Patricia Johann University of Strathclyde, UK Yukiyoshi Kameyama University of Tsukuba, Japan Marco T. Morazán (Chair) Seton Hall University, USA Rex Page University of Oklahoma, USA Fernando Rubio Universidad Complutense de Madrid, Spain Sven-Bodo Scholz University of Hertfordshire, UK Manuel Serrano INRIA
[Haskell-cafe] Re: Debugging methods for haskell
Fernan Bolando fernanbola...@mailc.net writes: On Thu, Jul 16, 2009 at 4:10 PM, Jon Fairbairnjon.fairba...@cl.cam.ac.uk wrote: I wonder if your code has to use !! at all? I took a look at a random module from the above link, and (without making much attempt at understanding it), I'd guess that using accumArray and friends would be more appropriate. Mostly you don't want to be doing indexing on lists. Most of the !! are used to access a list of parameters similar to accessing structures in C. Ah. I wondered why so many of them were x!!0. list!!constant is almost always something that could be done better. I am not particularly sure how to apply accumArray for something like that? You [probably] don't. My apologies for not looking more carefully (I really did just glance at it), but the remark about not using !! still stands. I've been trying to look at your source again, but the link doesn't respond to requests at the moment, so I can't be much help. Haskell has much richer mechanisms for doing structure-like things than C. Tuples and data types being the most obvious. -- Jón Fairbairn jon.fairba...@cl.cam.ac.uk ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Debugging methods for haskell
On Wed, Jul 15, 2009 at 11:13 PM, Don Stewartd...@galois.com wrote: fernanbolando: Hi all I recently used 2 hours of work looking for a bug that was causing Program error: Prelude.!!: index too large This is not very informative. It did not give me a hint which function was causing this. In C adding a few printf would have helped me, but in haskell I was not sure how to do that. Can anybody point me to some debuggin method everyone uses. You could: * use Debug.Trace.trace (equivalent of printf debugging) * use asserts: the 'assert' function * use the GHCi debugger to construct a stack trace * use profiling to construct a stack trace. * use the GHC head branch for first class stack traces, described in, Finding the needle: Stack Traces for GHC http://pubs.doc.ic.ac.uk/finding-the-needle/finding-the-needle.pdf Another option would be to use Safe.atMay[1] instead of !!. [1]: http://hackage.haskell.org/packages/archive/safe/0.2/doc/html/Safe.html#v%3Aat -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Haskell Zippers on Wikibooks: teasing! :)
On Thu, Jul 16, 2009 at 12:11 PM, Heinrich Apfelmusapfel...@quantentunnel.de wrote: Generic Programming: An introduction http://www.cse.chalmers.se/~patrikj/poly/afp98/ It's a bit verbose at times, but you only need the first few chapters to get an idea about polynomial functors (sums and pairs) and mu . Thanks, that's a really nice introduction, which seems to be at just my level for the moment! :-) D ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Leaner Haskell.org frontpage
Don Stewart wrote: Newbies: http://haskell.org Everything regular users need at fingertips http://dashboard.haskell.org/ That's fine. But please, no matter how minimalist the newbie page, make sure that there is a clear and prominent link there to the advanced page. Otherwise, if I happen to be somewhere without my bookmarks, it will take me a lot of fumbling in the dark to find it. Thanks, Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parsec for C or C++
I am working on a research language that is a variant of C. I'd like to use Parsec as the parser. Is there an existing Parsec parser for C or C++ (or Java) that could serve as a starting point? Thanks, Roy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec for C or C++
There is language.c http://www.sivity.net/projects/language.c/ http://hackage.haskell.org/package/language-c From a parsing standpoint, C++ is a massive departure from C. Good luck though. On Thu, Jul 16, 2009 at 12:25 PM, Roy Lowrance roy.lowra...@gmail.comwrote: I am working on a research language that is a variant of C. I'd like to use Parsec as the parser. Is there an existing Parsec parser for C or C++ (or Java) that could serve as a starting point? Thanks, Roy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- The greatest obstacle to discovering the shape of the earth, the continents, and the oceans was not ignorance but the illusion of knowledge. - Daniel J. Boorstin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec for C or C++
I too have a looming spectre of a C++ analysis project, one of the goals of the project is to be able to efficiently process huge volumes (read GBs) of code. Given the current benchmarks of language.c compared to the g++ front end. I was thinking of using an existing C++ parser written in C++, probably Elsa[1]. Then use haskell to analyze the resulting AST. [1] http://74.125.95.132/search?q=cache:7z7wl7oiy70J:www.eecs.berkeley.edu/~smcpeak/elkhound/sources/elsa/+elsa+c%2B%2Bcd=1hl=enct=clnkgl=usclient=firefox-a The link seems to be dead at the moment. On Thu, Jul 16, 2009 at 12:29 PM, Rick R rick.richard...@gmail.com wrote: There is language.c http://www.sivity.net/projects/language.c/ http://hackage.haskell.org/package/language-c From a parsing standpoint, C++ is a massive departure from C. Good luck though. On Thu, Jul 16, 2009 at 12:25 PM, Roy Lowrance roy.lowra...@gmail.comwrote: I am working on a research language that is a variant of C. I'd like to use Parsec as the parser. Is there an existing Parsec parser for C or C++ (or Java) that could serve as a starting point? Thanks, Roy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- The greatest obstacle to discovering the shape of the earth, the continents, and the oceans was not ignorance but the illusion of knowledge. - Daniel J. Boorstin -- The greatest obstacle to discovering the shape of the earth, the continents, and the oceans was not ignorance but the illusion of knowledge. - Daniel J. Boorstin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec for C or C++
Thanks Rick. A perfect tip! - Roy On Thu, Jul 16, 2009 at 12:29 PM, Rick Rrick.richard...@gmail.com wrote: There is language.c http://www.sivity.net/projects/language.c/ http://hackage.haskell.org/package/language-c From a parsing standpoint, C++ is a massive departure from C. Good luck though. On Thu, Jul 16, 2009 at 12:25 PM, Roy Lowrance roy.lowra...@gmail.com wrote: I am working on a research language that is a variant of C. I'd like to use Parsec as the parser. Is there an existing Parsec parser for C or C++ (or Java) that could serve as a starting point? Thanks, Roy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- The greatest obstacle to discovering the shape of the earth, the continents, and the oceans was not ignorance but the illusion of knowledge. - Daniel J. Boorstin -- Roy Lowrance home: 212 674 9777 mobile: 347 255 2544 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Leaner Haskell.org frontpage
On 15 Jul 2009, at 06:03, Richard O'Keefe wrote: On Jul 10, 2009, at 6:14 PM, Thomas Davie wrote: In my mind, the front page is for nothing more than enticing people to use Haskell for long enough to look at a second page where all the useful stuff is if you are a haskell programmer. I would have thought that a web page should serve its most frequent visitors best. By all means have an enticing paragraph at the top, pointing to a second page, but why make life hard for regular Haskellers visiting their site? Because regular haskellers are perfectly capable of bookmarking http://haskell.org/usefullstuff.html , while newbies will only get what google tells them -- the front page. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec for C or C++
Turns out that Language.C uses alex and happy. I'm looking to use Parsec. So back to the original question: Does anyone know of a C or java parser written using Parsec? - Roy On Thu, Jul 16, 2009 at 12:43 PM, Roy Lowranceroy.lowra...@gmail.com wrote: Thanks Rick. A perfect tip! - Roy On Thu, Jul 16, 2009 at 12:29 PM, Rick Rrick.richard...@gmail.com wrote: There is language.c http://www.sivity.net/projects/language.c/ http://hackage.haskell.org/package/language-c From a parsing standpoint, C++ is a massive departure from C. Good luck though. On Thu, Jul 16, 2009 at 12:25 PM, Roy Lowrance roy.lowra...@gmail.com wrote: I am working on a research language that is a variant of C. I'd like to use Parsec as the parser. Is there an existing Parsec parser for C or C++ (or Java) that could serve as a starting point? Thanks, Roy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- The greatest obstacle to discovering the shape of the earth, the continents, and the oceans was not ignorance but the illusion of knowledge. - Daniel J. Boorstin -- Roy Lowrance home: 212 674 9777 mobile: 347 255 2544 -- Roy Lowrance home: 212 674 9777 mobile: 347 255 2544 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] laziness blowup exercise
the strict functions seem very nice, will they eventually make their way into http://hackage.haskell.org/packages/archive/Stream/0.3.2/doc/html/Data-Stream.html ? where is Control.Monad.StreamT? couldn't find it. 2009/7/15 Bas van Dijk v.dijk@gmail.com: On Wed, Jul 15, 2009 at 3:02 AM, Thomas Hartmantphya...@gmail.com wrote: Please suggest more of these types of exercises if you have them and maybe we can collect the folk wisdom into a wiki page and/or exercise page for beginners. My 'stream' library[1] also has some examples. Look at the following functions in 'Data.Stream': * mapAccum' * scan' * iterate' * unfold' There are similar examples in 'Control.Monad.StreamT'. [1] http://code.haskell.org/~basvandijk/code/stream/ (Not on Hackage) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] laziness blowup exercise
I played with this a bit, and ok, it seems the difference between iterate' and iterate'' is h _ = 2 tit' = head . drop 1 . iterate' h $ undefined tit'' = head . drop 1 . iterate'' h $ undefined (Bas wishes for a type system that can express the different strictness properties of these functions...) Is this being worked on? Could you give some example of type systems that can express differences between functions of along dimension x? Off the top of my head, I guess (?) with dependent types can tell the difference between total and partial functions... partials won't even compile, right? Are there others? Pointers appreciated. ...seems the most lazy strict iterate. could you expand on what you mean by this? 2009/7/16 Bas van Dijk v.dijk@gmail.com: On Wed, Jul 15, 2009 at 6:35 PM, Ryan Ingramryani.s...@gmail.com wrote: iterate' f x = x `seq` x : iterate' f (f x) seems better; it doesn't evaluate list elements you don't visit. iterate'' f x = x : (iterate'' f $! f x) ...seems the most lazy strict iterate. (Bas wishes for a type system that can express the different strictness properties of these functions...) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A voyage of undiscovery
I've been working hard this week, and I'm stumbled upon something which is probably of absolutely no surprise to anybody but me. Consider the following expression: (foo True, foo 'x') Is this expression well-typed? Astonishingly, the answer depends on where foo is defined. If foo is a local variable, then the above expression is guaranteed to be ill-typed. However, if we have (for example) foo :: x - x as a top-level function, then the above expression becomes well-typed. I had never ever noticed this fact before. I'm still trying to bend my mind around exactly why it happens. As best as I can tell, top-level functions (and value constructors, for that matter) seem to get a new set of type variables each time they're used, but local variables each get a single type variable, so every mention of a local variable must be of the exact same type. Could this be what GHC's weird forall syntax is about? Does forall x. mean that x gets replaced with a unique type variable each time? It's an interesting hypothesis... Anyway, not that anybody is likely to care, but I've just spent an entire week writing a program which can type-check simple Haskell expressions. As in, you type in an expression and give types to any free variables it involves (including value constructor functions), and it tells you the type of the expression and all its subexpressions. (Or tells you that it's ill-typed.) It turns out that this is radically less trivial than you'd imagine. (The ramblings above being just one of the issues I blundered into. Others include the subtleties of writing an expression parser, building a pretty-printer with bracketing that works correctly, and the fact that expression processing malfunctions horribly if you don't make all the variable names unique first...) Other issues were mostly related to the difficulty of constantly refactoring code because you're not quite sure what you're trying to do or how you're trying to do it. (And obscure type checker warnings about GADTs...) Well there we are. I don't suppose anybody will be overly impressed, but I'm glad to have finally got it to work. Now, if it could parse more than 10% of Haskell's syntax sugar, it might even be useful for something... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Haskell as a first language?
I believe that from Scheme to Haskell is a natural transition, as I made the same transition myself. If you grasp the fundamental concepts of Scheme, Haskell seems like a step up. I will describe Haskell in terms of Scheme: # Haskell programs are more correct from the ground up Scheme will let you write (+ 2 2) and only tell you that it's wrong when it tries to run it (You can't add a number and a string!), whereas Haskell won't even let you run it until the types are correct. What some find difficult is ``1'' has type Num a = a, which means for all types a that are Numbers, a (or just all Number types), e.g. Integer, Double, Rational, etc. But this concept is found Scheme -- in Scheme you have all sorts of number types; ``+'' means add two numbers. In Haskell, we specify that notion explicitly. # Haskell is half wordy as Scheme Indeed, that is what drew me to Haskell away from Scheme. ## Problem 1 Consider the problem ``Double all the numbers in a list. In Scheme we might solve this problem like so: (map (lambda (n) (* n 2)) '(1 2 3 4) and the result would be (2 4 6). In Haskell, we can write the same: map (\n - n * 2) [1,2,3,4] and the result would be [2,4,6]. But we take it one step further: map (*2) [1,2,3,4] This means the same as the previous Haskell example. But the formal parameter ``x'' has been tripped away because it is redundant. ## Problem 2 Another problem, ``Given a list of lists, reverse all the lists and double each number in them.'' So in Scheme, we might solve this like so: (map (lambda (list) (reverse (map (lambda (n) (* n 2)) list))) '(1 2 3 4 5)) In Haskell, the same solution is rendered thusly: map (reverse . map (*2)) [1,2,3,4] The ``foo . bar'' is equivalent to (\x - foo (bar x)), or, in Scheme (lambda (x) (foo (bar x))). It's just that we have stripped the redundant formal parameters. ## Problem 3 Suppose our problem is ``Multiply the first three items of a list''. Our Scheme solution might be: (define (first-three-sum list) (* (car list) (cadr list) (caddr list))) In Haskell, we may write (admittedly, a better way to render this might be: firstThreeSum = sum . take 3): firstThreeSum (x:y:z:_) = x * y * z Here I have demonstrated pattern matching, a powerful and oft-used feature of Haskell for deconstructing a data structure, like a list or a tuple, based on a pattern. I'll abruptly stop here before I write a whole article. I'll summarize by saying that Haskell is the next step, a natural progression where things that you know all too well from Scheme become easier, and safer. The stuff described here is just the tip of the ice burg, of course. I wish that I had learned Haskell as my first programming language! Haskell takes a lot of effort to learn, but gives back in equal amounts. It is a rough ride to learn any programming language. If you think otherwise, you are not learning, or are learning wrongly. 2009/7/14 Simon Peyton-Jones simo...@microsoft.com Haskell is a great language! Check out haskell.org. I'm ccing the Haskell Cafe which is read by many people better qualified to answer your question than me. (Since I've been working on Haskell for many years, I am not well qualified to say how it seems to a beginner.) S | -Original Message- | From: Charles Turner [mailto:charlie.h.tur...@googlemail.com] | Sent: 11 July 2009 22:52 | To: Simon Peyton-Jones | Subject: Haskell as a first language? | | I'll make this short! Do you think Haskell is a good language to start | with? I am brand new to programming and have been using Scheme, some of | my peers suggest I should use Haskell. It seems professional to me. | Has features that a beginner should not worry about. What would you | suggest. (I'm not worried about bias) | | Thank you very much for your time. | | Charles Turner. ___ 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] A voyage of undiscovery
Consider the following expression: (foo True, foo 'x') Is this expression well-typed? Astonishingly, the answer depends on where foo is defined. If foo is a local variable, then the above expression is guaranteed to be ill-typed. However, if we have (for example) That's not true: main = let foo x = x in print (foo True, foo 'x') works like a charm. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A voyage of undiscovery
On Thu, Jul 16, 2009 at 2:34 PM, Andrew Coppinandrewcop...@btinternet.com wrote: I've been working hard this week, and I'm stumbled upon something which is probably of absolutely no surprise to anybody but me. Consider the following expression: (foo True, foo 'x') Is this expression well-typed? Astonishingly, the answer depends on where foo is defined. If foo is a local variable, then the above expression is guaranteed to be ill-typed. This isn't completely accurate: f0 _ = (foo True, foo 'x') where foo = id is well-typed. whereas f1 foo = (foo True, foo 'x') requires 'foo' to be polymorphic in its first argument. This does require a higher rank type, which can't be inferred: You could type f1 as f1 :: (forall a . a - a) - (Bool, Char) and apply it to 'id'. Or you could type it as something like: f1 :: (forall a . a - ()) - ((),()) and apply it to 'const ()' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] laziness blowup exercise
On Thu, Jul 16, 2009 at 7:45 PM, Thomas Hartmantphya...@gmail.com wrote: the strict functions seem very nice, will they eventually make their way into http://hackage.haskell.org/packages/archive/Stream/0.3.2/doc/html/Data-Stream.html Note that there are two stream packages: * 'Stream' by Wouter Swierstra (including some patches by me) which can be found on hackage. * 'stream' (with a lower case 'l') by me which isn't (yet) on hackage. My stream package started as a set of patches against Stream. However the goal Wouter had with Stream was to create a small education-friendly package focusing on simplicity. This is fine. The goal of stream however is to create an industrial-strength package, focusing on functionality and efficiency. Maybe I upload 'stream' to hackage if there's demand for it... where is Control.Monad.StreamT? couldn't find it. http://code.haskell.org/~basvandijk/code/stream/Control/Monad/StreamT.hs regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] laziness blowup exercise
On Thu, Jul 16, 2009 at 8:22 PM, Thomas Hartmantphya...@gmail.com wrote: I played with this a bit, and ok, it seems the difference between iterate' and iterate'' is h _ = 2 tit' = head . drop 1 . iterate' h $ undefined tit'' = head . drop 1 . iterate'' h $ undefined Exactly, iterate' first evaluates 'undefined' which is undefined. iterate'' returns 'undefined : iterate'' h 2'. Which then evaluates to: 'undefined : 2 : iterate'' h 2'. So both iterates are strict in their accumulator. They differ in when they force it. The former is more strict in that it forces its accumulator on entry while the latter is more lazy by first returning the accumulator and later forcing it. (Bas wishes for a type system that can express the different strictness properties of these functions...) Is this being worked on? I have no idea. regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A voyage of undiscovery
Robert Greayer wrote: f0 _ = (foo True, foo 'x') where foo = id is well-typed. Really? That actually works? How interesting... This suggests to me that where-clauses also do strange things to the type system. whereas f1 foo = (foo True, foo 'x') requires 'foo' to be polymorphic in its first argument. This does require a higher rank type, which can't be inferred: You could type f1 as f1 :: (forall a . a - a) - (Bool, Char) and apply it to 'id'. Or you could type it as something like: f1 :: (forall a . a - ()) - ((),()) and apply it to 'const ()' ...all of which is beyond Haskell-98, which is what I am limiting myself to at present. (Actually, even that is a lie. I don't have type-classes yet...) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Haskell as a first language?
In an ideal world, Haskell would be a perfect first programming language. But consider: If someone without any programming background learns Haskell as first language, she or he might have big problems using any other language after that. Unlearning what you can do with Haskell is much harder than unlearning imperative thinking. (I had to learn PHP after I was used to write in Haskell, and it was no fun) I don't want to miss the great experience of learning Haskell *after* Scheme (and Scheme after C), and I would not like to deprieve anybody of such an experience. Or what should they have for dessert? I don't know if that's a good argument. Best regards, Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A voyage of undiscovery
It's not where -- let also works let { foo Prelude let { foo x = x } in (foo 1, foo True) (1,True) Can you send the code you're trying that doesn't work? -Ross On Jul 16, 2009, at 3:40 PM, Andrew Coppin wrote: Robert Greayer wrote: f0 _ = (foo True, foo 'x') where foo = id is well-typed. Really? That actually works? How interesting... This suggests to me that where-clauses also do strange things to the type system. whereas f1 foo = (foo True, foo 'x') requires 'foo' to be polymorphic in its first argument. This does require a higher rank type, which can't be inferred: You could type f1 as f1 :: (forall a . a - a) - (Bool, Char) and apply it to 'id'. Or you could type it as something like: f1 :: (forall a . a - ()) - ((),()) and apply it to 'const ()' ...all of which is beyond Haskell-98, which is what I am limiting myself to at present. (Actually, even that is a lie. I don't have type-classes yet...) ___ 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] A voyage of undiscovery
On Thu, Jul 16, 2009 at 12:40 PM, Andrew Coppin andrewcop...@btinternet.com wrote: Robert Greayer wrote: f0 _ = (foo True, foo 'x') where foo = id is well-typed. Really? That actually works? How interesting... This suggests to me that where-clauses also do strange things to the type system. You could think of it that way. You mentioned GADTs in your OP. Well, it turns out GADTs often do not play nicely with where/let and it happens to all be related. As I understand it, functions bind their parameters monomorphically and let/where bind things polymorphically. And then we have the misfeature known as the monomorphism restriction which adds special cases. whereas f1 foo = (foo True, foo 'x') requires 'foo' to be polymorphic in its first argument. This does require a higher rank type, which can't be inferred: You could type f1 as f1 :: (forall a . a - a) - (Bool, Char) and apply it to 'id'. Or you could type it as something like: f1 :: (forall a . a - ()) - ((),()) and apply it to 'const ()' ...all of which is beyond Haskell-98, which is what I am limiting myself to at present. (Actually, even that is a lie. I don't have type-classes yet...) Congrats on the type inference engine you're writing. It's on my list of things to do, and I was even reading up on TaPL a month or two back, but I put it down and haven't picked it up again yet. I think writing one would help flush out my understand of all this stuff. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A voyage of undiscovery
Ross Mellgren wrote: It's not where -- let also works Prelude let { foo x = x } in (foo 1, foo True) (1,True) Awesome. So by attempting to implement Haskell's type system, I have discovered that I actually don't understand Haskell's type system. Who'd have thought it? Clearly I must go consult the Report and check precisely what the rules are... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] laziness blowup exercise
On Thu, Jul 16, 2009 at 8:22 PM, Thomas Hartmantphya...@gmail.com wrote: Is this being worked on? On Thu, Jul 16, 2009 at 12:35 PM, Bas van Dijkv.dijk@gmail.com wrote: I have no idea. Yes. Bolingbroke, Peyton-Jones. Types are calling conventions http://lambda-the-ultimate.org/node/3319 -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Haskell as a first language?
dvde: In an ideal world, Haskell would be a perfect first programming language. But consider: If someone without any programming background learns Haskell as first language, she or he might have big problems using any other language after that. Unlearning what you can do with Haskell is much harder than unlearning imperative thinking. (I had to learn PHP after I was used to write in Haskell, and it was no fun) I don't want to miss the great experience of learning Haskell *after* Scheme (and Scheme after C), and I would not like to deprieve anybody of such an experience. Or what should they have for dessert? FWIW, thousands of students from UNSW in Sydney learned Haskell as their first language throughout the 90s, before taking courses in C, Java, some scripting languages etc. Doesn't seem to have done any harm :) And you come away with a deeper appreciation of data structures and types. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] RE: Haskell as a first language?
2009/7/16 Daniel van den Eijkel d...@gmx.net: In an ideal world, Haskell would be a perfect first programming language. But consider: If someone without any programming background learns Haskell as first language, she or he might have big problems using any other language after that. Unlearning what you can do with Haskell is much harder than unlearning imperative thinking. (I had to learn PHP after I was used to write in Haskell, and it was no fun) I don't want to miss the great experience of learning Haskell *after* Scheme (and Scheme after C), and I would not like to deprieve anybody of such an experience. Or what should they have for dessert? I think the transition from one paradigm to another is always hard, whatever the direction. That's why it's a paradigm. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A voyage of undiscovery
Andrew Coppin wrote: Awesome. So by attempting to implement Haskell's type system, I have discovered that I actually don't understand Haskell's type system. Who'd have thought it? Clearly I must go consult the Report and check precisely what the rules are... I just read section 4.5 of the Haskell 98 Report. Ouch! _ I knew I'd be sorry I asked... Time for bed, I think! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Applying different functions to different types for lists
Hi, I want to build a framework to apply different functions to different types of lists and I want to generalize the solution as much as possible but my Haskell knowledge is not really enough to do this (I'm a haskell novice). The problem has two dimensions: 1. Lets say I have two functions: r13, ul : Char - Char where r13 returns the rot13ed character, and ul converts upper case chars to lower case and vice versa. Later I want a rot13 function that can operate on different types of lists and an uxl function that can also operate on different types of lists. 2. Lets say I have two kinds of lists to handle: String and Data.ByteString.Lazy as L. For Strings I want the updater function to be used for each character and for L I want all items to be converted to Char, the updater function to be updated and the result to be converted back to the original item type. Therefore I define a common class for handling these lists: class ListUpdater a where updateFn :: Char - Char update :: a - a so I can define the update function for the different types of lists: instance ListUpdater String where update = map updateFn instance ListUpdater L.ByteString where update = L.pack . (map updateFn) . L.unpack But now how should I glue these 2 dimensions together? How to say that I want a rot13 function that applies to any data type instantiated from ListUpdater and that is using the r13 function to do the update? And also that I want an uxl function that also applies to any data type instantiated from ListUpdater and that is using the ul function to do the update? Thanks, Istvan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Applying different functions to different types for lists
2009/7/16 Szekeres István szeke...@iii.hu: class ListUpdater a where updateFn :: Char - Char update :: a - a so I can define the update function for the different types of lists: instance ListUpdater String where update = map updateFn instance ListUpdater L.ByteString where update = L.pack . (map updateFn) . L.unpack So, as written, these functions both give an error, because updateFn isn't defined. Perhaps you want something like this: class CharMap a where charMap :: (Char - Char) - (a - a) instance CharMap Char where charMap f = f instance CharMap a = CharMap [a] where charMap f = map (charMap f) instance CharMap L.ByteString where charMap f = L.pack . map f . L.unpack Now you can write genericRot13, genericUL :: CharMap a = a - a genericRot13 = charMap rot13 genericUL = charMap ul -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Why is there no Zippable class? Would this work?
I was needing a way to zip generic data structures together today and was very annoyed to find that there is no Zippable class, or variant there of. So I made my own: class (Foldable f, Functor f) = Zippable f where fmaps :: (Foldable g) = g (a - b) - f a - f b fmaps' :: [a - b] - f a - f b -- to save a step on instance implementation zipWith :: (a - b - c) - f a - f b - f c zip :: f a - f b - f (a, b) unzip :: f (a, b) - (f a, f b) fmaps fs a = fmaps' (toList fs) a fmaps' fs a = fmaps fs a zipWith f a b = fmaps (fmap f a) b zip = zipWith (,) unzip a = (fmap fst a, fmap snd a) instance Zippable [] where fmaps' (fx:fs) (x:xs) = fx x : fmaps' fs xs fmaps' _ _ = [] --The fmaps function is also quite handy as a replacment for zipWith3, zipWith4, etc... --For example: x = [1, 3, 5, 7, 3] y = [6, 9, 3, 1, 4] z = [2, 4, 0, 8, 2] test = fmap (,,) x `fmaps` y `fmaps` z -- [(1,6,2),(3,9,4),(5,3,0),(7,1,8),(3,4,2)] --you can also throw in a functor instance to remove the dependency on the Functor class, but it -- might not be worth it: instance (Zippable f) = Functor f where fmap f a = fmaps (repeat f) a Is there any good reason that there isn't something like this in the standard libraries? Or, as far as I can tell, on hackage? If not, then maybe I'll stick it on hackage. - Job Vranish ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is there no Zippable class? Would this work?
I think there are some basic equivalents in the TypeCompose and category-extras packages, for the record, but a standalone version wouldn't hurt either! - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is there no Zippable class? Would this work?
Beautiful. Can we have a version on hackage? On Thu, Jul 16, 2009 at 5:56 PM, Job Vranishjvran...@gmail.com wrote: I was needing a way to zip generic data structures together today and was very annoyed to find that there is no Zippable class, or variant there of. So I made my own: class (Foldable f, Functor f) = Zippable f where fmaps :: (Foldable g) = g (a - b) - f a - f b fmaps' :: [a - b] - f a - f b -- to save a step on instance implementation zipWith :: (a - b - c) - f a - f b - f c zip :: f a - f b - f (a, b) unzip :: f (a, b) - (f a, f b) fmaps fs a = fmaps' (toList fs) a fmaps' fs a = fmaps fs a zipWith f a b = fmaps (fmap f a) b zip = zipWith (,) unzip a = (fmap fst a, fmap snd a) instance Zippable [] where fmaps' (fx:fs) (x:xs) = fx x : fmaps' fs xs fmaps' _ _ = [] --The fmaps function is also quite handy as a replacment for zipWith3, zipWith4, etc... --For example: x = [1, 3, 5, 7, 3] y = [6, 9, 3, 1, 4] z = [2, 4, 0, 8, 2] test = fmap (,,) x `fmaps` y `fmaps` z -- [(1,6,2),(3,9,4),(5,3,0),(7,1,8),(3,4,2)] --you can also throw in a functor instance to remove the dependency on the Functor class, but it -- might not be worth it: instance (Zippable f) = Functor f where fmap f a = fmaps (repeat f) a Is there any good reason that there isn't something like this in the standard libraries? Or, as far as I can tell, on hackage? If not, then maybe I'll stick it on hackage. - Job Vranish ___ 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] A voyage of undiscovery
On Thu, Jul 16, 2009 at 2:52 PM, Andrew Coppinandrewcop...@btinternet.com wrote: Ross Mellgren wrote: It's not where -- let also works Prelude let { foo x = x } in (foo 1, foo True) (1,True) Awesome. So by attempting to implement Haskell's type system, I have discovered that I actually don't understand Haskell's type system. Who'd have thought it? Clearly I must go consult the Report and check precisely what the rules are... The answer to your questions are on the back of this T-shirt. http://www.cafepress.com/skicalc.6225368 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Leaner Haskell.org frontpage
I asked why make life for regular Haskellers, and On Jul 17, 2009, at 4:56 AM, Thomas Davie replied: Because regular haskellers are perfectly capable of bookmarking http://haskell.org/usefullstuff.html , while newbies will only get what google tells them -- the front page. Sorry, but (1) I have a couple of hundred bookmarks; I may be a regular Haskeller, but it's better human interfacing for me to type www.haskell.org than to look things up in bookmarks. (2) Who says Google will only tell them the front page? PageRank means that Google will offer them first the page that is (to a first approximation) most linked to, and eventually that will be www.haskell.org/usefullstuff. (3) Right now, if you actually try it, Googling for Haskell gives you Haskell Introduction - HaskellWiki as the *second* link it offers. Are you really saying that there are lots of newbies who are smart enough to appreciate Haskell when they see it, but so excruciatingly dumb that they won't try Haskell Introduction? What might be a good thing would be if someone touched the introduction page from time to time. At the moment, it's about a year older than the main page, which makes it less inviting. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A voyage of undiscovery
Is everything an acceptable answer? -Ross On Jul 16, 2009, at 6:38 PM, Derek Elkins wrote: On Thu, Jul 16, 2009 at 2:52 PM, Andrew Coppinandrewcop...@btinternet.com wrote: Ross Mellgren wrote: It's not where -- let also works Prelude let { foo x = x } in (foo 1, foo True) (1,True) Awesome. So by attempting to implement Haskell's type system, I have discovered that I actually don't understand Haskell's type system. Who'd have thought it? Clearly I must go consult the Report and check precisely what the rules are... The answer to your questions are on the back of this T-shirt. http://www.cafepress.com/skicalc.6225368 ___ 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] Why is there no Zippable class? Would this work?
After rereading page 2 of McBride and Paterson's Functional Pearl, Applicative programming with effects, I think you are just reinventing Control.Applicative. The problem is that the default Applicative instance for [] is wrong, being a direct product rather than a direct sum. If [] were not already an instance of Applicative, you could easily define it as: import Control.Applicative data MyList a = Nil | (:::) a (MyList a) deriving (Read,Show,Eq,Ord) infixr 5 ::: -- same as [] instance Functor MyList where fmap f Nil = Nil fmap f (x ::: xs) = f x ::: fmap f xs -- different from [], sum rather than product instance Applicative MyList where pure x = x ::: Nil (*) (f ::: fs) (x ::: xs) = f x ::: (fs * xs) (*) _ _ = Nil x = (1::Int) ::: 3 ::: 5 ::: 7 ::: 3 ::: Nil y = (6::Int) ::: 9 ::: 3 ::: 1 ::: 4 ::: Nil z = (2::Int) ::: 4 ::: 0 ::: 8 ::: 2 ::: Nil test = (,,) $ x * y * z test (:::) (1,6,2) ((:::) (3,9,4) ((:::) (5,3,0) ((:::) (7,1,8) ((:::) (3,4,2) Nil Alternately, you could write a newtype for [] and give it the zippy instance for Applicative. Job Vranish wrote: I was needing a way to zip generic data structures together today and was very annoyed to find that there is no Zippable class, or variant there of. So I made my own: class (Foldable f, Functor f) = Zippable f where fmaps :: (Foldable g) = g (a - b) - f a - f b fmaps' :: [a - b] - f a - f b -- to save a step on instance implementation zipWith :: (a - b - c) - f a - f b - f c zip :: f a - f b - f (a, b) unzip :: f (a, b) - (f a, f b) fmaps fs a = fmaps' (toList fs) a fmaps' fs a = fmaps fs a zipWith f a b = fmaps (fmap f a) b zip = zipWith (,) unzip a = (fmap fst a, fmap snd a) instance Zippable [] where fmaps' (fx:fs) (x:xs) = fx x : fmaps' fs xs fmaps' _ _ = [] --The fmaps function is also quite handy as a replacment for zipWith3, zipWith4, etc... --For example: x = [1, 3, 5, 7, 3] y = [6, 9, 3, 1, 4] z = [2, 4, 0, 8, 2] test = fmap (,,) x `fmaps` y `fmaps` z -- [(1,6,2),(3,9,4),(5,3,0),(7,1,8),(3,4,2)] --you can also throw in a functor instance to remove the dependency on the Functor class, but it -- might not be worth it: instance (Zippable f) = Functor f where fmap f a = fmaps (repeat f) a Is there any good reason that there isn't something like this in the standard libraries? Or, as far as I can tell, on hackage? If not, then maybe I'll stick it on hackage. - Job Vranish ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A voyage of undiscovery
On Thu, Jul 16, 2009 at 08:52:40PM +0100, Andrew Coppin wrote: Ross Mellgren wrote: It's not where -- let also works Prelude let { foo x = x } in (foo 1, foo True) (1,True) Awesome. So by attempting to implement Haskell's type system, I have discovered that I actually don't understand Haskell's type system. Who'd have thought it? Clearly I must go consult the Report and check precisely what the rules are... actually, the rules are pretty straightforward. It doesn't matter where something is bound, just _how_ it is bound. Let-bound names (which includes 'where' and top-level definitions) can be polymorphic. lambda-bound or case-bound names (names bound as an argument to a function or that appear in a pattern) can only be monomorphic. And that's all there is to it. (the monomorphism restriction complicates it a little, but we don't need to worry about that for now) As an extension, ghc and jhc allow arguments and case bound variables to be polymorphic but only when explicitly declared so by a user supplied type annotation. (the exact rules for what 'explicitly declared' means can be a little complicated when formalized, but they match up enough with intuition that it isn't a problem in practice). They will never infer such a type on their own. John -- John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] another laziness blowup (this one unsolved)
Is it possible to fix alternate' (the second version), or otherwise define a fast stepwise alternate that doesn't blow up on long lists? alternate just breaks up [1,2,3,4,5] into ([1,3,5],[2,4]) Thanks! {-# LANGUAGE BangPatterns #-} import Data.List import Control.Arrow import Control.Parallel.Strategies t = (last *** last) $! alternate $ [1..(10^6)] t' = (last *** last) $! alternate' $ [1..(10^6)] t'' = (last *** last) $! alternate'' $ [1..(10^6)] -- finishes reasonably fast, but does a separate computation for the list and its tail rather than just rip through it alternate x = (skip1 x,(skip1 $ tail x)) skip1 = skip 1 skip n xs = let (a,b) = splitAt (n+1) xs in case a of [] - [] x:_ - x : skip n b -- this one overflows on million element list, even after fiddling with strictness on input args. can this be fixed? alternate' xs = let f3 :: Int - (([Int],[Int]),Int) - (([Int],[Int]),Int) f3 x ((a,b),n) = -- rnf (x,((a,b),n)) `seq` let nxtn = n+1 in if n `mod` 2 == 0 then ((x:a,b),nxtn) else ((a,x:b),nxtn) in fst . foldr f3 (([],[]),0) $ xs -- no overflow, goes through the list stepwise, but it's actually slightly slower than the first alternate because of the reverses alternate'' xs = let f3 ((a,b),n) x = (let nxtn = n+1 in if n `mod` 2 == 0 then ((x:a,b),nxtn) else ((a,x:b),nxtn) ) in (reverse *** reverse) . fst . foldl' f3 (([],[]),0) $ xs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Atom resources
The wiki [1] where Atom [2] once lived has been gone for some time now. The only resources I know for Atom are a couple blog posts, the haddock docs, and the Atom source on patchtag. Is anyone aware of other resources? Tom [1] http://funhdl.org/wiki/doku.php [2] http://hackage.haskell.org/package/atom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: another laziness blowup (this one unsolved)
solved. see the haskell wiki for spoiler: http://haskell.org/haskellwiki/Blow_your_mind 2009/7/16 Thomas Hartman tphya...@gmail.com: Is it possible to fix alternate' (the second version), or otherwise define a fast stepwise alternate that doesn't blow up on long lists? alternate just breaks up [1,2,3,4,5] into ([1,3,5],[2,4]) Thanks! {-# LANGUAGE BangPatterns #-} import Data.List import Control.Arrow import Control.Parallel.Strategies t = (last *** last) $! alternate $ [1..(10^6)] t' = (last *** last) $! alternate' $ [1..(10^6)] t'' = (last *** last) $! alternate'' $ [1..(10^6)] -- finishes reasonably fast, but does a separate computation for the list and its tail rather than just rip through it alternate x = (skip1 x,(skip1 $ tail x)) skip1 = skip 1 skip n xs = let (a,b) = splitAt (n+1) xs in case a of [] - [] x:_ - x : skip n b -- this one overflows on million element list, even after fiddling with strictness on input args. can this be fixed? alternate' xs = let f3 :: Int - (([Int],[Int]),Int) - (([Int],[Int]),Int) f3 x ((a,b),n) = -- rnf (x,((a,b),n)) `seq` let nxtn = n+1 in if n `mod` 2 == 0 then ((x:a,b),nxtn) else ((a,x:b),nxtn) in fst . foldr f3 (([],[]),0) $ xs -- no overflow, goes through the list stepwise, but it's actually slightly slower than the first alternate because of the reverses alternate'' xs = let f3 ((a,b),n) x = (let nxtn = n+1 in if n `mod` 2 == 0 then ((x:a,b),nxtn) else ((a,x:b),nxtn) ) in (reverse *** reverse) . fst . foldl' f3 (([],[]),0) $ xs ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is there no Zippable class? Would this work?
(I'm going to play fast and loose with constructors for this post, treating MyList and ZipList as if they were []) On Thu, Jul 16, 2009 at 4:10 PM, Dan Westonweston...@imageworks.com wrote: -- different from [], sum rather than product instance Applicative MyList where pure x = x ::: Nil (*) (f ::: fs) (x ::: xs) = f x ::: (fs * xs) (*) _ _ = Nil Unfortunately, this instance doesn't fulfill this Applicative law: pure id * f = f pure id * [1,2,3] = [id] * [1,2,3] = [id 1] = [1] Fortunately, the solution already exists in Control.Applicative: -- | Lists, but with an 'Applicative' functor based on zipping, so that -- -- @f '$' 'ZipList' xs1 '*' ... '*' 'ZipList' xsn = 'ZipList' (zipWithn f xs1 ... xsn)@ -- newtype ZipList a = ZipList { getZipList :: [a] } instance Functor ZipList where fmap f (ZipList xs) = ZipList (map f xs) instance Applicative ZipList where pure x = ZipList (repeat x) ZipList fs * ZipList xs = ZipList (zipWith id fs xs) In this case: pure id * [1,2,3] = [id, id, ...] * [1,2,3] = [id 1, id 2, id 3] = [1,2,3] -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is there no Zippable class? Would this work?
Way cool. I have gained newfound respect for what I don't know. :) Can there ever be more than one (observably different) valid definition of pure for a given * that obeys all the laws? I would imagine that there could be at most one. Dan Ryan Ingram wrote: (I'm going to play fast and loose with constructors for this post, treating MyList and ZipList as if they were []) On Thu, Jul 16, 2009 at 4:10 PM, Dan Westonweston...@imageworks.com wrote: -- different from [], sum rather than product instance Applicative MyList where pure x = x ::: Nil (*) (f ::: fs) (x ::: xs) = f x ::: (fs * xs) (*) _ _ = Nil Unfortunately, this instance doesn't fulfill this Applicative law: pure id * f = f pure id * [1,2,3] = [id] * [1,2,3] = [id 1] = [1] Fortunately, the solution already exists in Control.Applicative: -- | Lists, but with an 'Applicative' functor based on zipping, so that -- -- @f '$' 'ZipList' xs1 '*' ... '*' 'ZipList' xsn = 'ZipList' (zipWithn f xs1 ... xsn)@ -- newtype ZipList a = ZipList { getZipList :: [a] } instance Functor ZipList where fmap f (ZipList xs) = ZipList (map f xs) instance Applicative ZipList where pure x = ZipList (repeat x) ZipList fs * ZipList xs = ZipList (zipWith id fs xs) In this case: pure id * [1,2,3] = [id, id, ...] * [1,2,3] = [id 1, id 2, id 3] = [1,2,3] -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsec for C or C++
A parser for JavaScript (admittedly a much simpler beast) is part of Brown's WebBits: http://hackage.haskell.org/packages/archive/WebBits/0.15/doc/html/ BrownPLT-JavaScript-Parser.html Cheers, Sterl. On Jul 16, 2009, at 1:40 PM, Roy Lowrance wrote: Turns out that Language.C uses alex and happy. I'm looking to use Parsec. So back to the original question: Does anyone know of a C or java parser written using Parsec? - Roy On Thu, Jul 16, 2009 at 12:43 PM, Roy Lowranceroy.lowra...@gmail.com wrote: Thanks Rick. A perfect tip! - Roy On Thu, Jul 16, 2009 at 12:29 PM, Rick Rrick.richard...@gmail.com wrote: There is language.c http://www.sivity.net/projects/language.c/ http://hackage.haskell.org/package/language-c From a parsing standpoint, C++ is a massive departure from C. Good luck though. On Thu, Jul 16, 2009 at 12:25 PM, Roy Lowrance roy.lowra...@gmail.com wrote: I am working on a research language that is a variant of C. I'd like to use Parsec as the parser. Is there an existing Parsec parser for C or C++ (or Java) that could serve as a starting point? Thanks, Roy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- The greatest obstacle to discovering the shape of the earth, the continents, and the oceans was not ignorance but the illusion of knowledge. - Daniel J. Boorstin -- Roy Lowrance home: 212 674 9777 mobile: 347 255 2544 -- Roy Lowrance home: 212 674 9777 mobile: 347 255 2544 ___ 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] Atom resources
Are you starting a new Wiki? I'd absolutely love to have that resource. On Thu, Jul 16, 2009 at 8:14 PM, Thomas DuBuissonthomas.dubuis...@gmail.com wrote: The wiki [1] where Atom [2] once lived has been gone for some time now. The only resources I know for Atom are a couple blog posts, the haddock docs, and the Atom source on patchtag. Is anyone aware of other resources? Tom [1] http://funhdl.org/wiki/doku.php [2] http://hackage.haskell.org/package/atom ___ 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] Atom resources
No, I'm not starting a new wiki (though it someone does or has then it should go on haskell.org, imo). Tom On Thu, Jul 16, 2009 at 7:38 PM, John Van Enkvane...@gmail.com wrote: Are you starting a new Wiki? I'd absolutely love to have that resource. On Thu, Jul 16, 2009 at 8:14 PM, Thomas DuBuissonthomas.dubuis...@gmail.com wrote: The wiki [1] where Atom [2] once lived has been gone for some time now. The only resources I know for Atom are a couple blog posts, the haddock docs, and the Atom source on patchtag. Is anyone aware of other resources? Tom [1] http://funhdl.org/wiki/doku.php [2] http://hackage.haskell.org/package/atom ___ 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] Atom resources
That would be great. I can post some of my works on arduino , haskell and atom there. Radamés On Thu, Jul 16, 2009 at 23:54, Thomas DuBuissonthomas.dubuis...@gmail.com wrote: No, I'm not starting a new wiki (though it someone does or has then it should go on haskell.org, imo). Tom On Thu, Jul 16, 2009 at 7:38 PM, John Van Enkvane...@gmail.com wrote: Are you starting a new Wiki? I'd absolutely love to have that resource. On Thu, Jul 16, 2009 at 8:14 PM, Thomas DuBuissonthomas.dubuis...@gmail.com wrote: The wiki [1] where Atom [2] once lived has been gone for some time now. The only resources I know for Atom are a couple blog posts, the haddock docs, and the Atom source on patchtag. Is anyone aware of other resources? Tom [1] http://funhdl.org/wiki/doku.php [2] http://hackage.haskell.org/package/atom ___ 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] Why is there no Zippable class? Would this work?
Yeah I tried applicative, but saw that the * operator didn't do what I want with lists, and started looking elsewhere. I didn't even see the ZipList! Actually the other problem is that the data structure that I'm using won't support pure, so no Applicative :( Though for a generic zip, Applicative may be the better general purpose way to go. I didn't see TypeCompose and category-extras either those look pretty sweet :) Those would have worked. But I think I in my case, my version is a bit more general. Thanks for the input! It has been very enlightening. :) Hmmm I also should have pulled the zips out of the typeclass: class (Foldable f) = Zippable f where fmaps :: (Foldable g) = g (a - b) - f a - f b fmaps' :: [a - b] - f a - f b -- to save a step on instance implementation fmaps fs a = fmaps' (toList fs) a fmaps' fs a = fmaps fs a zipWith :: (Zippable f) = (a - b - c) - f a - f b - f c zipWith f a b = fmaps (fmap f a) b zip :: (Zippable f) = f a - f b - f (a, b) zip a b = zipWith (,) a b unzip :: (Functor f) = f (a, b) - (f a, f b) unzip a = (fmap fst a, fmap snd a) instance Zippable [] where fmaps' (fx:fs) (x:xs) = fx x : fmaps' fs xs fmaps' _ _ = [] On Thu, Jul 16, 2009 at 8:40 PM, Ryan Ingram ryani.s...@gmail.com wrote: (I'm going to play fast and loose with constructors for this post, treating MyList and ZipList as if they were []) On Thu, Jul 16, 2009 at 4:10 PM, Dan Westonweston...@imageworks.com wrote: -- different from [], sum rather than product instance Applicative MyList where pure x = x ::: Nil (*) (f ::: fs) (x ::: xs) = f x ::: (fs * xs) (*) _ _ = Nil Unfortunately, this instance doesn't fulfill this Applicative law: pure id * f = f pure id * [1,2,3] = [id] * [1,2,3] = [id 1] = [1] Fortunately, the solution already exists in Control.Applicative: -- | Lists, but with an 'Applicative' functor based on zipping, so that -- -- @f '$' 'ZipList' xs1 '*' ... '*' 'ZipList' xsn = 'ZipList' (zipWithn f xs1 ... xsn)@ -- newtype ZipList a = ZipList { getZipList :: [a] } instance Functor ZipList where fmap f (ZipList xs) = ZipList (map f xs) instance Applicative ZipList where pure x = ZipList (repeat x) ZipList fs * ZipList xs = ZipList (zipWith id fs xs) In this case: pure id * [1,2,3] = [id, id, ...] * [1,2,3] = [id 1, id 2, id 3] = [1,2,3] -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is there no Zippable class? Would this work?
Why is there no Zippable class? There is. You can use Data.Zippable from http://hackage.haskell.org/package/bff. It gives you a function tryZip :: Zippable k = k a - k b - Either String (k (a,b)) The Either in the return type is to capture an error message in case the two structures are not of the same shape. For example, for data Tree a = Leaf a | Node (Tree a) (Tree a) you would have: instance Zippable Tree where tryZip (Leaf a) (Leaf b) = Right (Leaf (a,b)) tryZip (Node a1 a2) (Node b1 b2) = do z1 - tryZip a1 b1 z2 - tryZip a2 b2 return (Node z1 z2) tryZip _ _ = Left Structure mismatch. Of course, you can get an unsafe zip by composing tryZip with a fromRight. What's more, the mentioned package contains an automatic Template Haskell deriver for Zippable instances, so you don't have to write the above instance definition yourself. The implementation is by Joachim Breitner. Ciao, Janis. -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:vo...@tcs.inf.tu-dresden.de ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Why is there no Zippable class? Would this work?
Why is there no Zippable class? There is. You can use Data.Zippable from http://hackage.haskell.org/package/bff. It gives you a function tryZip :: Zippable k = k a - k b - Either String (k (a,b)) The Either in the return type is to capture an error message in case the two structures are not of the same shape. This functionality can also be obtained from the generic programming library EMGM, with the function zip :: FRep3 ZipWith f = f a - f b - Maybe (f (a, b)) You can use Template Haskell to generate the necessary FRep3 instances. Once you have those you get many other generic functions for free. See http://hackage.haskell.org/package/emgm -- Johan Jeuring For example, for data Tree a = Leaf a | Node (Tree a) (Tree a) you would have: instance Zippable Tree where tryZip (Leaf a) (Leaf b) = Right (Leaf (a,b)) tryZip (Node a1 a2) (Node b1 b2) = do z1 - tryZip a1 b1 z2 - tryZip a2 b2 return (Node z1 z2) tryZip _ _ = Left Structure mismatch. Of course, you can get an unsafe zip by composing tryZip with a fromRight. What's more, the mentioned package contains an automatic Template Haskell deriver for Zippable instances, so you don't have to write the above instance definition yourself. The implementation is by Joachim Breitner. Ciao, Janis. -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:vo...@tcs.inf.tu-dresden.de ___ 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