Add Haskell to Perl 6 document #1188

WildYorkies opened this Issue Feb 10, 2017 · 10 comments


None yet

5 participants

@WildYorkies WildYorkies self-assigned this Feb 10, 2017

Don't forget to add info about laziness. It will be great to express in a simple way the model of Perl 6 laziness and to show how you can express something like

f = take 5 [1..]

in Perl 6.


@Altai-man Great idea! I could really use help, as I'm not an expert in either language 😄

Would it be easier if I just merged the file in the main repo right now and people edited from there?

Altai-man commented Feb 10, 2017 edited

I'm not sure, to be honest. I'm not aware of the actual number of haskellers(or near to) here, but I guess there are not so many to start their work in a hurry.
Judging by Ruby-related discussion(see #288) we need to firstly separate *-to-P6 files into a new directory. So it is more wise to make something much or less complete before any PR's.
And I doubt it should be the doc repository related issue, but I can't think of the place it should belong to quickly too. It is complicated.

Also, we can show how parsec family can be replaced with grammars(okay, you already noted that), how to use native types vs Data. related modules like Map. Expression of folds with [op], et cetera.

b2gills commented Feb 11, 2017 edited

I would like to see mentions of with without andthen orelse for dealing with defined/undefined values in the section about Maybe types.

A sum type looks to be more like an enum than a junction

enum Animal < Dog Cat Bird Horse >;

proto sub test-animal( Animal            ) {*}
multi sub test-animal( Dog                 ) { 'Woof' }
multi sub test-animal( Animal::Horse ) { 'Ney' }   # more explicit

say test-animal Animal::Dog; # more explicit
say test-animal Horse;

An alias should be an alias

alias Name = String

fullName :: Name -> Name -> Name
fullName first last = first ++ last

turns into

my constant Name = Str;

sub full-name ( Name \first, Name \last --> Name ) { first ~ last }

A subset with no where clause probably still incurs a performance penalty that an alias does not.

The greeting example could have looked more like a direct translation of Haskell

proto greeting ( Str --> Str ) {*}
multi greeting ( ""    --> "Hello, World!" ) {}
multi greeting ( "bub" --> "Hey bub." ) {}
multi greeting ( \name ) { "Hello, " ~ name ~ "!" }

I would add a note that using a variable name in the signature of the proto would provide more information in error messages, and for introspection.

proto greeting ( Str \name --> Str ) {*}

say &greeting.signature; # (Str \name --> Str)

multi greeting(Str \name where '' ) {'Hello, World!'}
multi greeting(Str \name where 'bub' )   {'Hey, bub.'}

I would add a note that where VALUE is the same as where $_ ~~ VALUE, and that the where clause can also be a Callable

multi greeting ( Str \name where { Bool.pick } --> 'True' ){}
multi greeting ( Str \name where &some-subroutine ){…}

It should also mention that the order of definition matters for routines with subset types / where clauses

multi greeting ( Str \name where '' --> 'Hello, World!' ){}
multi greeting ( Str \name where { Bool.pick } --> 'True' ){}
multi greeting ( Str \name where 'bub' --> 'Hey, bub.' ){}

say greeting ''; # will never say True
say greeting 'bub'; # about 50% of the time it will say True

All of the above also applies to the when construct

A note that [+] LIST is exactly the same as [+] 0, |List,
and [*] LIST is the same as [*] 1, |LIST might be good.
This is because the 0 argument multis for &infix:«+» returns 0 and &infix:«*» returns 1.

It should also note that the direction Left/Right/Chaining is determined by looking at the associativity attached to the operator/subroutine.

This applies to reduce as well.

sub two-elem-list ( \a, \b ) { ( a, b ) }

# you can use a subroutine as an infix operator
say 'a' [&two-elem-list] 'b'; # (a b)

# as the reduction prefix meta operator takes an infix operator, it will work there too;
[[&two-elem-list]] 1..5; # ((((1 2) 3) 4) 5)
say (1..5).reduce: &two-elem-list; # ((((1 2) 3) 4) 5)

# right associative
sub right-two-elem-list ( \a, \b ) is assoc<right>) { ( a, b ) }
say (1..5).reduce: &right-two-elem-list; # (1 (2 (3 (4 5))))

# XXX there is possibly a bug here as this currently doesn't look at
# XXX the associativity of &right-two-elem-list and just always does left assoc
say [[&right-two-elem-list]] 1..5;

# chaining
say [<] 1..5; # True
say (1..5).reduce: &[<]; # True
@coke coke added the docs label Feb 11, 2017
awwaiid commented Feb 11, 2017

With the ruby docs we decided that, once they were reasonably complete, we were better off having them published rather than waiting on a re-organization. I recommend that here as well -- do the organization separately.


@awwaiid in that case, I'll make the changes @b2gills suggests and merge the new file in.

How often does the website actually update based on changes in the github?


@WildYorkies it updates every 5-10 minutes or so, as far as I know.


@b2gills I have an issue open that we need code examples for andthen and orelse. At the moment, I'm not sure how they are expected to work in practice. I can guess, though.


Closing this since the file is up. Other issues can be opened for specific changes from here. Or just feel free to update it as you see fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment