13 ms·
Haskell to Perl 6
- devin 8y agoWhat’s the objective or rationale here? I don’t understand why this is interesting.
- deleted 8y ago[deleted]
- giggzy2 8y agoLanguage compare and contrast is whats interesting to me. I don't use either day to day but have had some exposure to both. I think both languages will have influence on future of language design at a minimum. Doubtful Perl does a phoenix routine but weirder things have happened.
- colomon 8y agoI'm not sure, but I've got to say, as someone with 10 years Perl 6 experience, I nevertheless learned useful new-to-me things in the second section of it.
- herrosheep 8y agoI'd like to hear opinions on how the use of sigils and the other syntax oddities like Int:D, Int:U, given, when, etc improves the codabliity/readability of Perl 6 vs other languages. The examples vs Haskell are not helping me understand. Personally I don't think the added verbosity is helping in any way.
- SwellJoe 8y agoCan you give an example of a language that is similarly precise with less verbosity, while still being comprehensible? Perl 6 is alarmingly concise in a lot of cases (hyper-operators come to mind), so it's super weird to see it called verbose. I'd wager that the ideal, or at least shortest, Perl 6 solution to most problems is shorter than most other languages...I don't know if it's necessarily more readable (you have to know a lot of the language to read really concise Perl 6 code, and there are many new concepts for most developers), but it's definitely not verbose. Int:D, Int:U, etc. provide information about types. They aren't arbitrary extra boilerplate. Every language with types specifies them in somewhat comparable ways. Perl 6 has gradual typing, you can use as much or as little of it as you want, and as suits your problem domain. You don't need those types, but if you use them well, you can do things more concisely...e.g. for multi-method dispatch based on type of arguments. given/when are keywords. Every language has keywords, and sometimes they'll be new ones that you haven't seen in other languages. Sigils, again, provide additional information, both to the reader and the compiler. Perl 6 is probably an improvement, or at least simplification, over Perl 5 in that the sigil is constant and doesn't reflect the usage. e.g. in Perl 5, when you want a single element of an array, you use $name[1], but when you want the whole array you use @name. The idea (sort of) being that $ is singular (a "scalar" value), while @ is plural. Some people don't like sigils, but I don't see any point in re-litigating it 30 years on. Perl has sigils. That's just how it do. Some like it, some don't. Enough Perl developers like it that it's never gone away.
- herrosheep 8y ago> Can you give an example of a language that is similarly precise with less verbosity, while still being comprehensible? This assumes I think Perl (6) is precise and comprehensible.
- SwellJoe 8y agoYou've already made it clear you have no experience with the language...so, what are you trying to accomplish here?
- tempodox 8y agoIf Perl is too verbose for you, you can always go to APL.
- 4thaccount 8y agoI think APL wins hands down in being the most concise when it comes to mathematical tasks, but P6 wins at more common scripting tasks such as parsing data. Only Rebol & Red in my opinion have similar constructs to P6's native grammars. Rebol wins at being the quickest way to write short GUI applications that do useful things as it uses its GUI dialect (basically a dsl) to make it really easy....almost unbelievably so (http://www.re-bol.com/rebol.html http://www.re-bol.com/rebol.html). I'd say powershell is the most concise way to deal with Windows automation. So really...all depending on what you mean.
- dima55 8y agoSigils have been standard in shells for decades. And sigils allow string interpolation to work; again, just like in normal unix shells. The python people decided that sigils are a bad idea, so instead of being able to say "I have $n apples" (like you could in shells we've all been using forever!) I now need to say "I have {} apples".format(n). I know which one I prefer!
- sqrt17 8y agoJavascript has `I have ${n} apples`, or even `This is chapter ${i+1}.` In terms of interpolation, that's the variant that I like best.
- erik_seaberg 8y agoPython added https://www.python.org/dev/peps/pep-0498/ https://www.python.org/dev/peps/pep-0498/.
- snapdangle 8y agoPerl 6 does it without the sigil outside the bracket :) "I have {some-complex-calc($i)} frobitzes"
- jdhzzz 8y agoAlso in groovy. I too am a fan.
- vorg 8y agoUnlike Python's `"I have {} apples".format(n)` and various shells' `"I have $n apples"`, Javascript's and Apache Groovy's `"This is chapter ${i+1}"` mean the lexer must make a call to the parser when lexing the string contents -- this allows `"This is ${"chapter"} ${i+1}"` to parse. Don't know about Javascript, but this makes Groovy's parser unreadable, and stuck on a very old version of Antlr, i.e. 2 instead of 4 (the latest).
- raiph 8y agoIn P6: grammar one-grammar { rule { <some-pattern> <another-grammar> .... } } Can't get simpler. Can't be more readable.
- Riverheart 8y agoPerl6's use of sigils seems excessive to me but I do like sigils for variables. It acts like a namespace between similarly named constructs. I know for instance WebClient is a class and $WebClient contains an instance of it. I also like how it makes it easy for syntax highlighters to identify variables from classes and keywords.
- colomon 8y agoI don't get the given/when part of this comment at all? given/when is exactly like C's switch/case, except the names are better and it's at least an order of magnitude more powerful. It's 100% not added verbosity in any way. Added complexity, sure, but it's a pretty straightforward application of some of the main ideas of the language, usable in the standard C-language-family way out of the box, and powerful and flexible when you understand it.
- dragonwriter 8y ago> I don't get the given/when part of this comment at all? Given and when were listed as separate items, not “given/when”; I agree with you about given (encompassing the given/when construct), but I can understand seeing “when” as an oddity (though I think it's a plus for comprehensibility, because it's general behavior is a consistent generalization of it's behavior in given/when.)
- lizmat 8y agoFWIW, with a little syntactic trick, you can actually have sigillless variables in Perl 6: my \foo = $ = 42; # bind sigilless name to a container with 42 say foo; # 42 foo = 666; say foo; # 666 See https://opensource.com/article/18/9/using-sigils-perl-6 https://opensource.com/article/18/9/using-sigils-perl-6 for more information. </plug>
- raiph 8y ago> The examples vs Haskell are not helping me understand. Personally I don't think the added verbosity is helping in any way. It doesn't sound to me like you are the right audience for the document you're reading. Quoting from that page: > this should not be mistaken for a beginner tutorial or overview of Perl 6; it is intended as a technical reference for Perl 6 learners with a strong Haskell background. It is not wise to start with a technical reference unless you are already fairly well versed in the basics of the technology you're learning and are motivated to deepen your knowledge of it. If you are interested in P6 you should start with overview or beginner material. Then, if you have a strong Haskell background, you can refer to the technical reference if and when the overview or beginner material isn't working for you. (If you are not genuinely motivated to have fun learning P6 then nothing related to P6 will work for you. Are you genuinely motivated to have fun learning P6?) ---- > I'd like to hear opinions on how the use of sigils and the other syntax oddities If you view childishly simple and natural syntax as "oddities" then your mind is already made up that they are oddities. So the rest of this comment is intended primarily for other readers and secondarily for you on the off chance that you are able to transcend your mind's confirmation bias against the following constructs actually being simple and natural. > use of sigils Many programmers think in terms of three fundamental primitive data types from which all other datatypes are composed: * single items * collections of numbered things * collections of named things P6 adopts this view and assigns three sigils to these three abstract notions. This makes it both easier and quicker to both read and write code -- once you've learned how they work. In P5 sigils were onerously complex. In P6 they are childishly simple. So now it's also easy and quick to learn them as well as to use them.[1] > Int:D, Int:U In P6, every type that's created using any of its type constructors is a sum type with two sub-types. This includes types defined in the standard language such as Int. The sub-types are named D and U. For example, to refer to Int's D sub-type, use `Int:D`. This makes it easy and quick to read and write code once you've learned what they are. Fortunately, it's childishly simple to learn what they are.[2] > given The `given` keyword means essentially the same as the English word `given`. This makes it easy and quick to read and write code once you've learned the English meaning of `given`.[3] > when The `when` keyword hides a good deal of complexity. But one can hop on Wittgenstein's Ladder easily. Because for the first rung, it just means the same as the meaning of the English word `when` used in the context of something that's `given`. The keyword `when` makes it easy and quick to read and write code once you've learned the English meaning of `when` in the context of `given` -- and it can then be used in other contexts.[4] ---- [1] 27 second vide clip covers it all: https://www.youtube.com/watch?v=Nq2HkAYbG5o&t=10m&list=PLRuESFRW2Fa77XObvk7-BYVFwobZHdXdK&index=92 https://www.youtube.com/watch?v=Nq2HkAYbG5o&t=10m&list=PLRuE... [2] They're called "type smilies" for a reason. :D is the definite, happy, valuable type. What's `42`? Simple. Definite. Happy. Valuable. Unlike :D, the other subtype, :U, is undefined, unhappy, not a value. What's `Int`? Is it `42`? No, because that would be defined. Every value/object is either definite/happy or it isn't. [3] From dictionary.com: given: noun: "an established fact" [4] From dictionary.com: when: conjunction: "in the event that"
- dragonwriter 8y ago> I'd like to hear opinions on how the use of sigils and the other syntax oddities like Int:D, Int:U, given, when, etc improves the codabliity/readability of Perl 6 vs other languages. Given/when is not really a syntax oddity, it's (in the simplest case), a structurally and semantically common construct in other languages that goes by various names (case/when, switch/case, etc.), the name is unique to Perl but the naming fis all over the map between other languages, and Perl matches English much better than most others (though it would do so more precisely if “when” was “when it is”), so that's a plus for readability except for people who come to Perl more fluent in some other programming language than in English. Other uses of when might be unique to Perl, but they generalize the use from given/when (and have the much the relation to English), so there is a deep consistency there; learning a concept that is more limited in other languages buys you more in Perl.
- empath75 8y agoIt seems to me that Haskell programmers are the least likely to need something like this.
- herrosheep 8y agoRight. This is like saying "Hello most elite gamers, here is an entry level tutorial to Duke Nukem Forever..."
- snapdangle 8y agoDuke Nukem Forever jokes, really? Look, Perl 6 can either be a "crazy complex" language that is "over-designed" and "hard to read", or it can some sort of toy with laughable complexity (your supposition is that Perl 6 is to elite programmers as Duke Nukem Forever is to elite gamers). So which is it? Complex enough for only elites to grasp? Or just some toy language with no real capabilities, let alone unique features of interest to elite programmers?
- herrosheep 8y agoI think you misunderstood or are trolling. This is a Haskell to Perl 6 guide. Haskell is for the elite programmers. Perl 6 is the Duke Nukem Forever of programming languages. This of course was all tongue in cheek.
- snapdangle 8y agoSorry dude, but the crux of your joke is that elite programmers shouldn't look at Perl 6.. because it took a while to develop? And it is hardly "tongue in cheek" when you talk trash about the language (which you have never used) throughout this news item.
- kingofhdds 8y agoTo be interested in programming languages generally, I think, is an inherent feature of a passionate programmer.
- justinator 8y agoIt may be that it's of interest, as an early Perl 6 implementation was written in Haskell (Pugs)
- knbknb 8y agoI think this Haskell version (pugs) came at a time when perl6-development was somewhat stuck, and it enabled the Perl 6 developers to test new language constructs on an improved runtime (I believe); so Haskell was actually key to Perl 6 development. (https://gist.github.com/masak/479846/4908b28645b8815d1afe2b4d79efa164984b759c https://gist.github.com/masak/479846/4908b28645b8815d1afe2b4...)
- bmn__ 8y agoHTML, more readable: http://strangelyconsistent.org/blog/happy-10th-anniversary-perl-6 http://strangelyconsistent.org/blog/happy-10th-anniversary-p...
- rs86 8y agoPerl 6 feels a bit "ad hoc" to me... It looks like it has very interesting features but it lacks the uniformity present in most languages...
- nine_k 8y agoPerl has never been about uniformity. Perl is a great experiment in language design, or, rather, a battery of experiments. It's the opposite of a cleanly designed language.
- herrosheep 8y agoI do agree that Perl (6) is not a cleanly designed language.
- lizmat 8y agoWould you care to elaborate on the non-clean parts in your opinion?
- herrosheep 8y agoThings like this seem like odd design choices: my @menu = <hamburger fries milkshake>; say @menu.contains('hamburger'); # True say @menu.contains('hot dog'); # False say @menu.contains('milk'); # True! say @menu.contains('er fr'); # True! say @menu.contains(<es mi>); # True!
- raiph 8y agoEnglish contains ambiguous words. What does "contains" mean in the previous sentence? In P6 it means searching a string for a substring. Your code asks P6 to treat @menu as a string. If you want to treat it as a list and grep that list then use grep: my @menu = <hamburger fries milkshake>; say so @menu.grep('hamburger'); # True say so @menu.grep('hot dog'); # False say so @menu.grep('milk'); # False say so @menu.grep('er fr'); # False say so @menu.grep(<es mi>); # False
- cwyers 8y agoThere's also a Python version of this[1], which starts with a discussion about Perl 6's equivalent of print, which is put. This makes no sense to me whatsoever, as print is both a much easier way to say it and _what was used in Perl 5_, but not my circus, not my monkeys. But then it goes on to say: > There is also say, which behaves similarly, but will call the gist method of its argument. And after having read the linked-to docs for say[2] and gist[3], I not only cannot understand what is being said, I have no idea how anyone else could, either. 1) https://docs.perl6.org/language/py-nutshell https://docs.perl6.org/language/py-nutshell 2) https://docs.perl6.org/routine/say https://docs.perl6.org/routine/say 3) https://docs.perl6.org/routine/gist https://docs.perl6.org/routine/gist
- _delirium 8y agoI've never used Perl6, but it took me about 30 seconds to figure out what 'say' and 'gist' do from the linked docs? 'gist' prints a string representation of an object aimed at being human-readable at the expense of not necessarily being a complete representation (e.g. the doc page gives an example that an array has only its first 100 elements printed followed by a '...'). 'say' is a version of 'put' that does this for every object being printed.
- cwyers 8y agoSo, I sort of took that away from it, but there's stuff in the gist page like: > The default gist method in Mu re-dispatches to the perl method for defined invocants, and returns the type name in parenthesis for type object invocants. Many built-in classes override the case of instances to something more specific that may truncate output. And I have no idea how anyone that isn't already fluent in Perl 6 is expected to read that. EDIT: My point is mostly that it just seems... weird. Like, I get the animating idea of Haskell, even if I don't understand all of the concepts. Perl 6 just seems... alien. It's incredibly funky.
- kqr 8y agoI have no problem reading that. Sure, I dont understand it in fine technical detail (what's Mu? An implementation of Perl? A codename for Perl 6?) But I believe I understand enough of it to start using it. This specific example seems similar to the __repr__ vs __str__ thing in Python, and not very alien at all.
- kev6168 8y agoPerl 6 is for people who are very smart and have a great spirit in seeking and having fun in programming, I really admire that. That's my thought after two failed attempts (each lasted about two days) to learn it in 2012 and 2014. I felt the use of sigils, syntax oddities and the cleverness were beyond my ability to master the language. I should mention in 1998 I used (modified it a little bit) Selena Sol's shopping cart script. Since then I have only written a few small Perl 5 scripts, am not familiar with recent development. To learn Perl 6 today, what kind of practice projects/applications, or approaches, one can use?
- johnisgood 8y ago> Perl 6 is for people who are very smart and have a great spirit in seeking and having fun in programming Not sure why you felt the need to include this. How did you come to this conclusion? Is this in comparison to Haskell, or what?
- kev6168 8y agoIt was tongue in cheek, haha... I was only frustrated by my own inability to get the hang of Perl 6. As an old casual fan of Perl, I still want to take another shot at learning it very much.
- 4thaccount 8y agoThe perl6intro website shows you the essentials of what you need and the ecosystem has matured a lot since 2014 as well as many good books being published. Laurent Rosenfield has a Think Perl6 book that you can buy in paper or read online for free. If you can already code, getting proficient in basic Perl6 is easy. Becoming a master is outside my current grasp.
- kev6168 8y agoThanks for the recommendations. One liners are fun, and life-saving. I am curious about this aspect compared to Perl 5. With Perl 6's new syntax and language features, can we still easily [ab]use one liners for fun and profit?
- rurban 8y agoThe lack of maybe or nullable types in perl6 with the need to check for definedness at run-time (Int:D) is one of its major design blunders. Also this syntax! In cperl I rather use proper maybe types as in every other language. ?Int is (Int | Undef) you cannot use Int? as this would confuse the parser to look for the matching :
- raiph 8y ago> The lack of maybe or nullable types in perl6 P6 supports something more powerful and uses that instead: https://en.wikipedia.org/wiki/Tagged_union https://en.wikipedia.org/wiki/Tagged_union In P6 the symbol Int, when treated as a type by the compiler, denotes Int:_, which is a sum type, with two subtypes, namely a generically existentially quantified Int (Int:D) and a generically universally quantified Int (Int:U). Thus Int can be used in the role of a nullable type, but is an improvement in the sense that the equivalent to None (Int:U) encodes its type. In P6 all constructable types are automatically sum types with :U and :D subtypes. > need to check for definedness There is relatively little need for users to check definedness. The language and compiler ensure basic type/memory safety and the user can just write code and it'll automatically be type safe at this basic level. When the need arises, the user only need type one or two characters in almost all cases (either `:D` if writing a type constraint or `if foo` or `?foo` if writing an explicit check). > at run-time In P6 definedness refers to the notion that something actually exists and this is deliberately aligned with the notion that something exists at run-time. Users seldom need to concern themselves with this but when they do the P6 approach is simple and convenient. > one of its major design blunders. Also this syntax! I see the Int, Int:D, Int:U semantics and syntax as a design triumph. See another comment in this thread for an introduction to my view: https://news.ycombinator.com/item?id=18647590 https://news.ycombinator.com/item?id=18647590 > I rather use proper maybe types as in every other language. When I read things like "proper" and "as in every other language" in this manner I experience them as appeals to authority. Perl 6 is not a typical language. Just as Perl 5 isn't either. For example, a P6 compiler is allowed to statically check that types match at compile time: sub foo (Str $bar) {} foo 42 yields the compile time error: Error while compiling .code.tio Calling foo(Int) will never work... but it doesn't view static type checking as a panacea any more than it considers dynamic type checking as a panacea. P6, like Perl, is designed around the notion of a this and that view of things rather than an either/or view.
- hestefisk 8y agoNot to be trollish, but is anyone actually using Perl 6 for more than just for kicks? It is a super interesting language, but has it been battle tested over the years similar to Perl 5?
- sacomo 8y agoWe are using in in production. One of our bigger uses is a DB metrics aggregator. We use it to to pull stats from DB servers for remote clients and dump them into graphite. Sort of an agent-less monitoring platform. We've had this Perl 6 tool running 24/7 since last summer. It's now pulling from ~80 DB servers. Another internal use is an AWS infrastructure management tool that we built. A cli util that handles the initial bootstrapping for new AWS projects and a few helper features to simplify some of our common management tasks. Perl 6 has been pretty easy to work with. Even in situations where a module isn't available or the requirements are too complex to build it with Perl 6 within our project time constraints, its facilities as a glue language really make it simple to work with external tools, modules, libs. If you like the Perl 6 syntax then I'd recommend just spending some time with it. It's stable and fast enough for regular use now.
- cutler 8y agoPerl 6 is still 9 times slower than Perl 5 when parsing log files with a regex. I don't quite get why the feature which made Perl famous has now taken a back seat. Why should I take a 9x performance hit?
- vvillena 8y agoThe Perl 5 core is hack upon hack, to the point that it's been mostly abandoned due to how hard is to change things without breaking anything. Perl 6 was born as a specification, which allows for a "first make it right, then make it fast" approach.
- cutler 8y agoThat's assuming it can be made fast. It's been stagnant around this level of performance for quite some time now.
- benbristow 8y agoI still can't take Perl 6 seriously with that butterfly logo. Website looks like it's from 2003 as well.
- g82918 8y agoIf the logo is an issue, how do you feel about the Go gopher? Or Glenda the plan9 bunny?
- benbristow 8y agoAt least the Go Gopher/Glenda are kinda minimal
- xaduha 8y agoUse this one https://rakudo.org https://rakudo.org
- benbristow 8y agoSee that looks nice and the website looks like it was made this decade.
- ktpsns 8y agoActually Perl 6 comes off badly in this comparison. The Haskell expressions are almost always easier to read, understand, reproduce, and overall even shorter. Nevertheless it shows that Perl 6 can do real functional programming. Even if the syntax looks exceptional sometimes, even for people familiar with Perl 5.
- raiph 8y agoIt's not a comparison. It's not an appetizer for P6 or ways in which P6 comes off better than Haskell. It's not an overview or tutorial for learning P6 if you come from a Haskell background. It's for someone who has already decided they like P6, has learned the basics, and wants to tighten up their understanding of P6 as it relates to Haskell things they know. It deliberately picks things that are basic in Haskell even if they're not so basic in P6. That's why it says: > Note that this should not be mistaken for a beginner tutorial or overview of Perl 6; it is intended as a technical reference for Perl 6 learners with a strong Haskell background.
- ktpsns 8y agoYou're certainly right, but that doesn't change my point that, by just looking at the code, Haskell seems to have the better solutions for the problems. This conclusion is clearly unfair because the author tried to port simple Haskell solutions to Perl.
- raiph 8y ago> You're certainly right, but that doesn't change my point that, by just looking at the code, Haskell seems to have the better solutions for the problems. Sure. But that's an inevitable consequence of what the document aims to achieve. The problems chosen were the ones for which Haskell had simpler solutions. The point of the document was to help someone who is already motivated to learn P6 and knows Haskell to get to grips with P6. If the point were to motivate someone who knows Haskell to want to learn P6 then the examples chosen would be ones for which the P6 solution is better than the Haskell one.