[Haskell-cafe] Arrows: definition of pure & arr

Peter Verswyvelen bf3 at telenet.be
Tue Feb 19 11:04:39 EST 2008

Ah, "pure" stands for "pure arrow". I found this confusing since I consider all functions in Haskell (except unsafeXXX and maybe IO) to be "pure". So pureArrow would be good but is so loooong ;-)

Actually, if you look at the way OO programmers design code, they usually choose long descriptive names, like "FindElementByName". Most Haskell people seem more math oriented and use very short names, like "fst" and "snd" (which are a bit better than the old "car" and "cdr"). Now in the end, once you get used to a name, it doesn't matter does it? 

But when I show typical Haskell code to object-oriented friends of mine, they get scared because it looks like math, with all the symbols and short names. But if I show code like

render $ 
	solid (rectangle (position 100 100) (size 400 50)) `inColor` red 
	line (position 50 50) (position 150 150) `withLineSize` 4 `inColor` blue 

and compare that to what this would like when using C++ (or C# with WPF...), they go... wow... The only question they tend to ask is "what does the $ and `` do?". 

And if I tell them I designed this mini-language myself in Haskell in a few lines of code without lexing and yaccing, they can hardly believe it. 

Mmm, maybe this is a good one for "Why functional programming matters", but for the experienced Haskellers, the above DSL stuff is probably too obvious.

So even if I don't know much of Haskell yet, the ability to write these small DSLs so compactly and elegantly is what one of things I really like about the language.

E.g. for my students, I wrote a little "3D vector math" exercise generator in a couple of hours. This tool generates algebraic exercises and shows the solutions step by step by performing simplification, using indented pretty printing. I would never have been able to do that in C++ or C# in such a short time and so compactly, even though I have +15 years more experience with the latter language. But in Haskell, even though I hardly know the language, it was "easy". I now want to use GTK2HS to generate PDFs from these exercises that also shows step-by-step geometrical solutions (but that's work in progress ;)

PS: Wolfgang also seems to use nice names in Grapefruit for his types, e.g.

act :: PlainCircuit (IO output) output
createPlainCircuit :: PlainCircuit input output -> input -> IO (output, IO ())

instead of 

act :: PlainCircuit (IO a) a
mkPlainCircuit :: PlainCircuit a b -> a -> IO (b, IO ())

What is the general "style guide" regarding this?

> -----Original Message-----
> From: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-
> bounces at haskell.org] On Behalf Of Wolfgang Jeltsch
> Sent: Tuesday, February 19, 2008 11:29 AM
> To: haskell-cafe at haskell.org
> Subject: Re: [Haskell-cafe] Arrows: definition of pure & arr
> Am Sonntag, 17. Februar 2008 14:32 schrieb Peter Verswyvelen:
> > I don't get why the name isn't "arrow" instead of "arr"... Arr
> reminds
> > me of pirates, "arrrrrrrhh" ;-)
> > I guess "first" was chosen because "fst" was already taken, but then
> it
> > would be logical to choose "arrow" instead of "arr" ;-)
> arr has two problems in my opinion.  First, it is an unneccessarily
> truncated
> name.  Is it really so difficult to type two letters more?  Second, it
> doesn’t describe its purpose very well.  Okay, it constructs an arrow.
> But
> (>>>) and first do this as well.  pure makes much more sense to me,
> since it
> says that it constructs *pure* arrows.
> If you look at Grapfruit’s source code, you probably won’t find any
> occurences
> of arr (but you’ll find Arrow.pure rather often).
> Best wishes,
> Wolfgang
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.516 / Virus Database: 269.20.7/1286 - Release Date:
> 2/18/2008 6:49 PM

More information about the Haskell-Cafe mailing list