Live data from Hacker News

Haskell to Perl 6

docs.perl6.org

91–100 of 136 posts

Re: Haskell to Perl 6

#91
post #53
post #37

Earlier quoted context omitted.

> Except the resulting code will look nothing like “the humans say it”, Actually, I find it maps rather directly to how a lot of people explain things. For example, "Examine each number, and as long as it's greater than 10 and odd, then pass it to the the work function." for my $number ( @numbers ) { next unless $number > 10; next unless $number % 2; work($number); } Perl generally allows you to structure your code a…

That ought to be a oneliner in any sane language today: numbers.into_iter().filter(|n| n>10 && n%2!=0).for_each(work); map work . filter ((/=0) . (`mod` 2)) . filter (>10) $ numbers Insert tirade about how for-loops are free to do so much that they are slower-to-comprehend than specific-purpose iterator/list functions, here.

The language is happy to accommodate any style you like best, including oneliners.

    sub work($n) { say $n }
    my @numbers = 1..100;

    # rubyish
    @numbers.grep(* > 10 && * %% 2).map(&work);

    # lol turbo haskal
    map &work  10  grep * > 10 ==> grep * %% 2 ==> map &work;
The traditional function composition operator exists, see https://docs.perl6.org/routine/%E2%88%98

Re: Haskell to Perl 6

#92
post #74

Earlier quoted context omitted.

I do agree that Perl (6) is not a cleanly designed language.

Would you care to elaborate on the non-clean parts in your opinion?

Things like this seem like odd design choices:

  my @menu = ;
  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();                # True!

Re: Haskell to Perl 6

#93

Earlier quoted context omitted.

Right. This is like saying "Hello most elite gamers, here is an entry level tutorial to Duke Nukem Forever..."

Duke 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…

I 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.

Re: Haskell to Perl 6

#94

Earlier quoted context omitted.

The linguistic target Larry Wall aims at has little to do with uttering the line of code out loud.. The attempt to mirror human language is in the flexibility of the constructs. This is the much maligned There Is More Than One Way To Do It (TMTOWTDI) principle. The language is designed to allow the programmer to express themselves in they way that makes the point best for their brains. Now, this is almost a classical…

Hmm, interesting. TMTOWTDI is great for a small (one person) script, and One Way is better for a large (multi person) code base? That seems very plausible.

The downside of TIMTOWTDI is that the next person that comes along might not be as familiar with the alternate way you chose to implement something, which impedes understanding. That's never really an issue for a single person program, since they had to understand that feature it to initially write it, meaning they should understand it when they encounter it later (the vast majority of time at least. Forgetting skills from long ago happens).

Re: Haskell to Perl 6

#95

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. The examples vs Haskell are not helping me understand. Personally I don't think the added verbosity is helping in any way.

> 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=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"

Re: Haskell to Perl 6

#96
post #70

Actually 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.

It'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.

Re: Haskell to Perl 6

#97
post #88
post #33

Earlier quoted context omitted.

Javascript has `I have ${n} apples`, or even `This is chapter ${i+1}.` In terms of interpolation, that's the variant that I like best.

Unlike 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 (t…

In P6:

grammar one-grammar { rule { .... } }

Can't get simpler. Can't be more readable.

Re: Haskell to Perl 6

#98
post #95

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. The examples vs Haskell are not helping me understand. Personally I don't think the added verbosity is helping in any way.

> 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 wi…

Was actually very interesting in your reply until

  > etc

  I haven't seen that one.
Made me wonder if this was honest or not.

Re: Haskell to Perl 6

#99
post #95

Earlier quoted context omitted.

> 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 wi…

Was actually very interesting in your reply until > etc I haven't seen that one. Made me wonder if this was honest or not.

It breaks HN's civility rule to insinuate dishonesty in other users. Please review the site rules at https://news.ycombinator.com/newsguidelines.html.

Re: Haskell to Perl 6

#100
post #37

Earlier quoted context omitted.

> Except the resulting code will look nothing like “the humans say it”, Actually, I find it maps rather directly to how a lot of people explain things. For example, "Examine each number, and as long as it's greater than 10 and odd, then pass it to the the work function." for my $number ( @numbers ) { next unless $number > 10; next unless $number % 2; work($number); } Perl generally allows you to structure your code a…

One can write pretty much the same code in python/c++11/whatnot and it also feels quite natural to read: for number in numbers: if number Do you have a better example where the Perl syntax would shine?

You have clearly been able to read and translate the GP's code and confidently assert you've written "pretty much the same code".

> Do you have a better example where the Perl syntax would shine?

Unless you have "a ton of knowledge about Perl" your reply shows that it was a perfect example in response to the GGP.

Post reply on HN