tag:blogger.com,1999:blog-7094652.post6533572309110447811..comments2024-03-23T14:36:09.980+00:00Comments on Neil Mitchell's Blog (Haskell etc): Describing Haskell to an Ada programmerNeil Mitchellhttp://www.blogger.com/profile/13084722756124486154noreply@blogger.comBlogger16125tag:blogger.com,1999:blog-7094652.post-90422714461526221452018-10-26T14:14:38.610+01:002018-10-26T14:14:38.610+01:00Sorry, identation was lost in my comment. Thanks, ...Sorry, identation was lost in my comment. Thanks, if somebody could tell me, how to correct this with the restrictions of the HTML tags.<br /><br />T. Tempelmeierhttp://www.th-rosenheim.denoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-79831773241535264372018-10-26T14:02:22.076+01:002018-10-26T14:02:22.076+01:00Hi, in Ada as follows
function sort (xs : Ar...Hi, in Ada as follows<br /><b> <br /> function sort (xs : ArrayInt) return ArrayInt is<br /> begin<br /> if xs'length <= 1 then return xs;<br /> else<br /> declare<br /> pivot : constant integer := xs(xs'length/2);<br /> begin<br /> return sort(filter(xs, pivot, greater)) &<br /> filter(xs, pivot, equal) &<br /> sort(filter(xs, pivot, less));<br /> end;<br /> end if;<br /> end sort;<br /></b><br />An Ada real-time programmer would not do it this way, though. Do you know, why?<br /><br />It is always interesting again and again, how people are locked in their world. <br />Ada folks: learn a bit of functional programming!<br />Haskell folks: be open for other domains (realtime, embedded)!<br /><br />Another version with a kind of "closure" and "named lambda-like" local functions.<br /><br /><b><br /> function sort (xs : ArrayInt) return ArrayInt is<br /> begin<br /> if xs'length <= 1 then return xs;<br /> else<br /> declare -- my kind of "closure" <br /> -- with three "named lambda-like" functions defined where needed<br /> pivot : constant integer := xs(xs'length/2);<br /> function greater (x:integer) return boolean is (pivotx);<br /> begin<br /> return sort(filter(xs, greater'access)) &<br /> filter(xs, equal'access) &<br /> sort(filter(xs, less'access));<br /> end; -- Ende of declare block<br /> end if;<br /> end sort;<br /></b><br /><br />Oh, please note: the parameter xs of sort is immutable anyway by default. No need <br />to make it constant explicitely.<br /><br />And: the generic version needs a bit more; can't just write "Ord" as in Haskell, <br />but have to specify that <, >, = must be available. <br />Genericity in Ada is usually statically resolved during compile time. Quite nice, <br />when flying in an airplane... How is it done in Haskell? Please help me with this, <br />I really would like to learn about.<br /><br />Let's bring together the functional and the realtime world, in order to learn as <br />much as possible from those thinking in the other world!<br />T. Tempelmeierhttp://http.th-rosenheim.denoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-79106096309269593632015-03-09T03:25:18.171+00:002015-03-09T03:25:18.171+00:00What is your basis for saying Ada is a horrid lang...What is your basis for saying Ada is a horrid language? In my experience it is a far better language than C or C++ because it offers language tools that help prevent errors such as a strong type system.Nelsonhttps://www.blogger.com/profile/10091802480561628341noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-14788759882045094432011-03-23T00:28:52.228+00:002011-03-23T00:28:52.228+00:00I wrote a fully generic QuickSort in about 100 lin...I wrote a fully generic QuickSort in about 100 lines; it would be MUCH shorter if a) it were not generic and b) if I gave no thought to picking pivots.OneWingedSharkhttps://www.blogger.com/profile/15679642433389790180noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-9850676852907852992010-07-04T10:09:21.502+01:002010-07-04T10:09:21.502+01:00solrize: I don't think I'd recommend Ada t...solrize: I don't think I'd recommend Ada to anyone who wasn't writing something to run on a resource constrained embedded chip. It's really quite a horrid language...Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-53708240450456124832010-07-04T01:03:24.744+01:002010-07-04T01:03:24.744+01:00Nice post, I guess. Could you consider doing one ...Nice post, I guess. Could you consider doing one about describing Ada to a Haskell programmer? In particular I'm wondering about Ada as a possible replacement for C and C++, if I'm looking for something with Haskell-like type safety but able to operate with C-like machine resource constraints.solrizenoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-3782289058086274462009-03-19T22:13:00.000+00:002009-03-19T22:13:00.000+00:00"The example they wanted me to show them "in a fun...<I>"The example they wanted me to show them "in a functional style" was:<BR/><BR/>x := 1;<BR/>x := x + 1;</I><BR/>You could have pointed out that this code is pointless unless you do something with x afterwards.<BR/><BR/>As for sequencing, Haskell does have the 'sequence' function...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-27562230541847866252007-05-03T13:53:00.000+01:002007-05-03T13:53:00.000+01:00"I then challenged them to write quicksort in Ada,..."I then challenged them to write quicksort in Ada, which is really quite hard to do."<BR/><BR/>Huh? I did it as an excercise. It's no harder than doing it in C if you understand Ada generics.Harald Korneliussenhttps://www.blogger.com/profile/02909854185625282505noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-40052589631037365652007-03-12T13:12:00.000+00:002007-03-12T13:12:00.000+00:00Functional programming as a concept does not rely ...Functional programming as a concept does not rely on interacting with the world, and does not require IO or IORefs. If you start by teaching someone what Imperative Haskell (TM) looks like, then they'll never know the beauty of pure Haskell.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-9308120030948135782007-03-12T12:34:00.000+00:002007-03-12T12:34:00.000+00:00No desctructive assignment? What are my IORefs the...No desctructive assignment? What are my IORefs then? No sequencing? What are my monads for then?Harald Korneliussenhttps://www.blogger.com/profile/02909854185625282505noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-41003798614939848832007-03-11T15:01:00.000+00:002007-03-11T15:01:00.000+00:00I don't think Monad's is fair on them, their brain...I don't think Monad's is fair on them, their brain would pop. Plus it's confusing to say there is no assignment, then show them something that looks a lot like assignment.<BR/><BR/>I wouldn't normally have brought up lazy evaluation, but since they were 100% focused on "worst case execution time", lazy evaluation is a nice spanner in the works.Neil Mitchellhttps://www.blogger.com/profile/13084722756124486154noreply@blogger.comtag:blogger.com,1999:blog-7094652.post-79568532830598894732007-03-11T14:31:00.000+00:002007-03-11T14:31:00.000+00:00Lazy evaluation is more difficult to master in imp...Lazy evaluation is more difficult to master in imperative languages, but it is certainly doable.<BR/>A controlled and simple lazy evaluation strategy in the imperative context is delayed writing to the disk.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-63218371951277383662007-03-11T08:54:00.000+00:002007-03-11T08:54:00.000+00:00I'm not sure lazy evaluation in an imperative lang...I'm not sure lazy evaluation in an imperative language makes much sense. Imperative languages nearly all rely on side effects which wouldn't be guaranteed to happen with lazy evaluation.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-38079634857550210632007-03-11T07:14:00.000+00:002007-03-11T07:14:00.000+00:00Lazy evaluation has nothing to do with functional ...Lazy evaluation has nothing to do with functional programming. You can get it in imperative languages as well.<BR/>Again, monads have nothing to do with functional programming.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-18654894371359492742007-03-11T02:20:00.000+00:002007-03-11T02:20:00.000+00:00Haskell wasn't so strange for me since I had seen ...Haskell wasn't <I>so</I> strange for me since I had seen Prolog before and that had opened my eyes to the idea that you can write code that doesn't <I>do</I> anything, it just <I>describes</I> something. Letting go of imperative programming was the hard part. (The really perverse thing in Haskell is that the imperative programming--monads--seems to be the hardest part.)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7094652.post-35383769823315186192007-03-10T17:09:00.000+00:002007-03-10T17:09:00.000+00:00Why don't you tell them what a monad is? This will...Why don't you tell them what a monad is? This will be really cruel.Anonymoushttps://www.blogger.com/profile/16208105530458618755noreply@blogger.com