add haskell-to-p6 file #1193

Merged
merged 20 commits into from Feb 12, 2017

Projects

None yet

6 participants

@WildYorkies
Contributor

No description provided.

doc/Type/Sub.pod6
42♥;
# OUTPUT: «I love 42!␤»
sub postcircumfix:<⸨ ⸩>(Positional $a, Whatever){ say $a[0], '…', $a[*-1] }
[1,2,3,4]⸨*⸩;
# OUTPUT: «1…4␤»
constant term:<♥> = "♥"; # We don't want to quote "love", do we?
- sub circumfix:<α ω>($a){ say „$a is the beginning and the end.“ };
@Altai-man
Altai-man Feb 12, 2017 Member

Why such changes?

doc/Language/haskell-to-p6.pod6
+In Haskell, you can alias an existing type to simply increase clarity of intent and re-use
+existing types.
+
+ alias Name = String
@Altai-man
Altai-man Feb 12, 2017 Member

What is this alias thing? Did you mean type Name = String?

doc/Language/haskell-to-p6.pod6
+=Multiple Dispatch
+
+Haskell makes heavy use of multiple dispatch in function definitions.
+
@Altai-man
Altai-man Feb 12, 2017 Member

It is indeed kinda multiple dispatch, but I think that "pattern matching" will suit here better for haskellers, wont it?

@WildYorkies
Contributor

@Altai-man Good catches.

@timo
Member
timo commented Feb 12, 2017

i'm not sure why there was a change to Sub.pod6 in between those other commits? it doesn't seem to belong to the haskell-to-p6 pull request, i think.

@WildYorkies
Contributor

@timo It was leftover from a changed I wanted to make but never submitted. fixed now

doc/Language/haskell-to-p6.pod6
+ sub parse-int(Str $s --> Int) { ... }
+
+ given parse-int($string) {
+ when * ~~ Int:D { * }
@CIAvash
CIAvash Feb 12, 2017 Contributor

Shouldn't { * } be { $_ }?

Also, you can just write when Int:D { $_ } and when Int:U { 0 }.

@timo
timo Feb 12, 2017 Member

Maybe here would be a good place to put a note about the defined-or operator //? Or is that too tangential?

@WildYorkies
WildYorkies Feb 12, 2017 Contributor

@CIAvash Good call.

@timo I talked about orelse (which is basically defined-or). But I'm just trying to get this initial draft merged so others can contribute to it.

doc/Language/haskell-to-p6.pod6
+
+It should be noted that in Perl6, one can also created a subset of an existing type.
+
+ subset Name of String where { *.chars < 20 };
@CIAvash
CIAvash Feb 12, 2017 Contributor

This should be subset Name of Str where *.chars < 20;

Also a typo in the line above, "created" => "create"?

@CIAvash
Contributor
CIAvash commented Feb 12, 2017

I think ==> and <== feed operators should be mentioned too. But of course they don't have to be part of this pull request.

@WildYorkies
Contributor

@CIAvash Agreed. I have a placeholder for those under the heading "Currying" I believe.

+function.
+
+ proto greeting ( Str --> Str ) {*}
+ multi greeting ( "" --> "Hello, World!" ) {}
@awwaiid
awwaiid Feb 12, 2017 Contributor

Putting a constant string as the return type feels weird to me.

@WildYorkies
WildYorkies Feb 12, 2017 Contributor

I would imagine that it does, as many things do in P6 😄

I'm not sure a debate has been had on the merits of this style or not. But I do think that having constraints on the return type in the signature brings benefits in regards to more exact contracts, no?

@awwaiid
awwaiid Feb 12, 2017 Contributor

Yes, but that would be more like multi greeting ( "" --> Str ) { "Hello, World!" }. It is the combining of the value and the thus implicitly the type on the return value that I find odd, though it seems to be allowed. Funnily I don't feel that way on the parameter itself. Might be my own taste.

@b2gills
b2gills Feb 12, 2017 Contributor

This document is for people coming from Haskell.

As such it makes sense to use syntax that would seem more familiar to them.

It also means that no matter what code you put in the routine, it always returns the expected value.

Then there is the benefit that calling .signature.returns on the routine tells you exactly what it returns.

@WildYorkies
WildYorkies Feb 12, 2017 Contributor

How do you feel about multi is-thing(Thing $ --> True) {} ?

@awwaiid
awwaiid Feb 12, 2017 Contributor

I'm fine leaving this as-is overall I suppose, the feedback that it tickled my senses is enough.

--> True is a fun one! It makes me feel conflicted :) . I guess in a case like that my wish would be for multi is-thing(Thing $) { True } to be the equivalent, so that the value and the type are statically known/inferred by the compiler.

Anyway -- is fine, I don't feel super strong about it, and it definitely works the way you have it.

doc/Language/haskell-to-p6.pod6
+
+It should be noted that in Perl6, one can also create a subset of an existing type.
+
+ subset Name of String where *.chars < 20;
@CIAvash
CIAvash Feb 12, 2017 Contributor

You forgot to change String to Str.

@WildYorkies WildYorkies merged commit e425ca4 into perl6:master Feb 12, 2017

1 check was pending

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@WildYorkies
Contributor
WildYorkies commented Feb 12, 2017 edited
  • Make sure this shows up on the initial Language page index on the website
  • Make sure this is linked to on the "resources" of the website when it is good and ready
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment