5 ms·
In my experience, pure functional programming, combined with Haskell's relatively permissive syntax, allows for very natural-language-like and well-structured p
by wyager 12y ago
In my experience, pure functional programming, combined with Haskell's relatively permissive syntax, allows for very natural-language-like and well-structured programs.
Languages like Agda can do this even more impressively. You can do stuff like write
if_then_else_ : Bool -> a -> a -> a
And you can split up the "if", "then", and "else" and put the arguments where the underscores are.
- taeric 12y agoMeh. I think it is arguable that the code from this article is as easy as it is to understand as much from the prose that goes with it as from the language it is written in. My argument would actually lean towards more so.
- Dewie 12y ago> I think it is arguable that the code from this article is as easy as it is to understand as much from the prose that goes with it as from the language it is written in. This was hard to understand.
- taeric 12y agoApologies. I think I should have just written that in multiple sentences. I don't think mere commas can save it. Simply put, my assertion is that it is the accompanying prose and diagrams that truly make the code easy to understand. Not its implementation language. I would love to say that my terrible sentence above illustrates that prose is not a panacea. Well, I think I can claim that. I can not claim it was intentional. :)
- pmoriarty 12y agoFor what it's worth, I found your original statement perfectly clear.
- eru 12y ago> Simply put, my assertion is that it is the accompanying prose and diagrams that truly make the code easy to understand. Not its implementation language. Haskell does help somewhat, in that it's offers you a lot of flexibility in how to structure your program. So you can tailor your program to your explanation. (Knuth's literate programming tools help bring those capabilities and more to more conventional languages.)
- Retra 12y agoThe mixfix notation in Agda seems really amazing. I am always wishing I could write code like "add _ to _" or "sort _ by _", etc...
- beagle3 12y agoIt's almost exactly smalltalk (circa 1980 or so) notation.
- Peaker 12y agoAgda mixfix supports things like: [ foo ] bar ! ! baz etc. It also supports precedence parsing. I don't Smalltalk can do all of these. Smalltalk, unlike Agda, can probably omit the spacing around operators, though, while Agda can't :)
- beagle3 12y agoI probably should look more closely at Agda. But the if_then_else_ example is basically smalltalk equivalant - although I suspect Agda will be able to do without the angle brackets that Smalltalk often needs in these cases.
- chriswarbo 12y agoMaude also allows mixfix like Agda. There's an interesting example in the manual ( http://maude.cs.uiuc.edu/maude1/manual/maude-manual-html/maude-manual_31.html http://maude.cs.uiuc.edu/maude1/manual/maude-manual-html/mau... ) where juxtaposition is defined as an operation, specifically: op __ : Bits Bits -> Bits [assoc] . The underscores are placeholders for arguments, just like in Agda, but there's no name defined! Since `0` and `1` are defined as constructors of `Bit` (which is a sub-type of `Bits`) this will parse values like `0101010` as `Bits`.
- eru 12y agoHaskell has sortBy and comparing, like this: sortBy (comparing salary) employees The grammar is not as close to English, but close enough to understand.
- Dewie 12y agoShouldn't the then- and else-"branches" be made lazy?
- eru 12y agoThey probably are already. (In Haskell, they would be by default. I don't know enough about Agda.)
- andolanra 12y agoThat is indeed the case. In Agda, the default is call-by-name, which means that functions are applied before arguments are evaluated. This does not, however, include sharing, so evaluating (λ x → x + x) (fib 2000) will evaluate `fib 2000` twice. Agda programs can also be compiled to Haskell, in which case they would have Haskell's evaluation strategy, which is generally call-by-need (and so would share the result of fib 2000 above.)
- tel 12y agoI've never been aware of whether Agda is CBN or CBV because it actually doesn't matter (!). In a pure, terminating language like Agda evaluation is "confluent" which means that CBV and CBN evaluations are identical.
- mercurial 12y agoInteresting. So "if foo then" would be a valid partial application?