Live data from Hacker News

Haskell to Perl 6

docs.perl6.org

101–110 of 136 posts

Re: Haskell to Perl 6

#101

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.

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

Re: Haskell to Perl 6

#102
post #52

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.

I 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 flex…

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

Re: Haskell to Perl 6

#103
post #74

Earlier quoted context omitted.

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!

English 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 = ;
    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();                # False

Re: Haskell to Perl 6

#104

Earlier quoted context omitted.

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

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

You've already made it clear you have no experience with the language...so, what are you trying to accomplish here?

Re: Haskell to Perl 6

#105
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.

Here is a slight modification that takes advantage of the hyper operator >> (»):

  @numbers.grep(* > 10 && * % 2)>>.&work;
https://docs.perl6.org/language/operators#index-entry-hyper_...

Re: Haskell to Perl 6

#106
post #4

It seems to me that Haskell programmers are the least likely to need something like this.

A great Haskeller led to this document being made available. [1]

She didn't question whether Haskellers needed something like P6, she just implemented it and pushed Haskell to greater heights. I think that is a worthwhile point.

But I don't understand why you've introduced your point about what you perceive as the level of need for this document.

Given a non-zero number of lang X to lang Y documents, one or more of them will be the most likely needed, one or more the least likely. And given such a scenario, it'll likely seem one way to some folk and another to others. So?

----

[1] The first P6 compiler prototype was written by Audrey Tang. https://en.wikipedia.org/wiki/Audrey_Tang The P6 project follows several principles she established such as being optimized for fun, and a "forgiveness > permission" policy for most contributions. So someone wrote a nice doc and it's been made available.

Re: Haskell to Perl 6

#107
post #74

Earlier quoted context omitted.

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!

From https://docs.perl6.org/routine/contains, `contains` coerces its invocant to a string and searches for a substring starting from a certain position (index 0 by default):

    # Let's drop `` (quote-words constructor) and 
    # use a more familiar array of strings:
      
    my @menu = 'hamburger', 'fries', 'milkshake';
      
    # Let's look at the definition of the `Str` method in 
    # the `List` class from which the `Array` class inherits:
    
    #`{
      method Str(List:D: --> Str:D)
      Stringifies the elements of the list and joins
      them with spaces (same as .join(' ')).
    }

    # Thus, after being stringfied, @menu is treated as 
    # the string 'hamburger fries milkshake'
    
    # With this is in hand, we can gauge the possible
    # result of the following statements:
    
    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


If you'd like instead to search the array for words as elements, we could use Perl 6's set functions. However, I don't know if they're as performant as regular string searches:

    say 'hamburger' (
`∈` is the unicode equivalent of `(---

I'm not sure if I'm missing something in the "odd design choices" in this specific case so it'd be great if you could elaborate a little bit further here.

Re: Haskell to Perl 6

#108
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…

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

Probably your comment hints to this already in which case the following will be redundant but I wanted to mention them more explicitly. This is mainly for people unfamiliar with Perl 6.

Using the type smileys(:U, :D) are also ways to specifically match against a type object (`Int`, `Str`, `Rat`, etc.) and an instance object of a type object (-5, 'Hello', 1/5, etc.):

    Int ~~ Int:U;   # True
    -5  ~~ Int:U;   # False
    -5  ~~ Int:D;   # True
    Int ~~ Int:D;   # False
There is also the :_ smiley which is used by default whenever the other two aren't specified:

    Int ~~ Int;     # True, same as: Int ~~ Int:_;
    -5  ~~ Int;     # True, same as: -5  ~~ Int:_;

Re: Haskell to Perl 6

#109

Earlier quoted context omitted.

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!

From https://docs.perl6.org/routine/contains , `contains` coerces its invocant to a string and searches for a substring starting from a certain position (index 0 by default): # Let's drop ` ` (quote-words constructor) and # use a more familiar array of strings: my @menu = 'hamburger', 'fries', 'milkshake'; # Let's look at the definition of the `Str` method in # the `List` class from which the `Array` class inherits:…

The ASCII equivalent of `∈` is `(elem)`.

Re: Haskell to Perl 6

#110
post #79
post #26

Earlier quoted context omitted.

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

As pointed out by others, Mu is the most undefined value there is in Perl 6 and the base root for the immediate child classes ( https://docs.perl6.org/images/type-graph-Mu.svg ). However, most classes (both built-in and user-defined ones) don't inherit directly from it. Instead, they inherit from Any, which in turns inherits from Mu. More info about it: - https://docs.perl6.org/type/Mu - https://en.wikipedia.org/wiki…

Right. Here's a blog post, which, while not directly about Mu (it's about m, a shell script I wrote), has many excerpts about (the original) Mu (from which Perl6's Mu descends, pun intended, ha ha) near the end - some may find them interesting:

m, a Unix shell utility to save cleaned-up man pages as text:

https://jugad2.blogspot.com/2017/03/m-unix-shell-utility-to-...

Post reply on HN