Skip to content

Commit

Permalink
POD not Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
b2gills committed Feb 14, 2017
1 parent 09a4093 commit 5a14552
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions doc/Language/haskell-to-p6.pod6
Expand Up @@ -4,7 +4,7 @@
=SUBTITLE Learning Perl 6 from Haskell, in a nutshell: What do I already know?
Haskell and Perl6 are _very_ different languages. This is obvious. However, that
Haskell and Perl6 are I<very> different languages. This is obvious. However, that
does not mean there are not similarities or shared ideas! This page attempts to
get a Haskell user up and running with Perl6. The Haskell user may find that they need
not abandon all of their Haskelly thoughts while scripting in Perl6.
Expand All @@ -28,7 +28,7 @@ You do not mix types and values in Haskell like the below
plusTwo 2 -- This is valid
plusTwo Integer -- This is not valid
In Perl6, types (AKA type objects) can live on the same level as values
In Perl6, types (AKA type objects) live on the same level as values
sub plus-two(Int $x --> Int) { $x + 2 }
Expand Down Expand Up @@ -66,12 +66,12 @@ and Undefined objects. Plain type objects are undefined while instantiated objec
So in Perl6 we have type constraints that indicate the definedness of a type. These are
- Int:D # This is a defined Int.
- Int:U # This is an undefined Int, AKA a type object
- Int:_ # This is either defined or undefined.
Int:D # This is a defined Int.
Int:U # This is an undefined Int, AKA a type object
Int:_ # This is either defined or undefined.
If we wanted to be explicit in the above example (probably a good idea), we could add
the `:_` constraint on the return type. This would let the user know that they should account
the C<:_> constraint on the return type. This would let the user know that they should account
for both defined and undefined return values. We could also use other methods and constructs
that specifically test for definedness.
Expand All @@ -94,11 +94,11 @@ that specifically test for definedness.
# With the defined-or operator
parse-int($string) // 0
The `with` operator that you see above is like `if`, except it explicitly tests for definedness and then
passes the result to the following block. Similarly, `without` tests that the object is undefined and also
The C<with> operator that you see above is like C<if>, except it explicitly tests for definedness and then
passes the result to the following block. Similarly, C<without> tests that the object is undefined and also
passes the result to the following block.
For more natural control flow with undefined and defined types, Perl6 introduces `andthen` and `orelse`.
For more natural control flow with undefined and defined types, Perl6 introduces C<andthen> and C<orelse>.
my $result = parse-int($string) orelse 0;
Expand Down Expand Up @@ -198,24 +198,24 @@ Haskell makes heavy use of pattern matching in function definitions.
greeting "bub" = "Hey bub."
greeting name = "Hello, " ++ name ++ "!"
Perl6 does this as well! You just use the `multi` keyword to signify that it is a multiple dispatch
Perl6 does this as well! You just use the C<multi> keyword to signify that it is a multiple dispatch
function.
proto greeting ( Str --> Str ) {*}
multi greeting ( "" --> "Hello, World!" ) {}
multi greeting ( "bub" --> "Hey bub." ) {}
multi greeting ( \name ) { "Hello, " ~ name ~ "!" }
The `proto` declarator is not necessary, but can sometimes aid in making sure that all multis
The C<proto> declarator is not necessary, but can sometimes aid in making sure that all multis
follow your business rules. 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)
An interesting thing to note in the Perl6 code above is that passing values like `'bub'` as a
function parameter is just syntax sugar for a `where` guard.
An interesting thing to note in the Perl6 code above is that passing values like C<'bub'> as a
function parameter is just syntax sugar for a C<where> guard.
=Guards
Expand All @@ -235,8 +235,8 @@ used behind the scenes to constrain our function arguments.
multi greeting(Str \name where $_ ~~ '' ) {'Hello, World!'}
multi greeting(Str \name where $_ ~~ 'bub') {'Hey bub.'}
`$_` is known as the topic variable. It assumes the form of whatever is appropriate. The smart match
operator `~~` figures out the best way to determine if the left matches the right, be it number ranges,
C<$_> is known as the topic variable. It assumes the form of whatever is appropriate. The smart match
operator C<~~> figures out the best way to determine if the left matches the right, be it number ranges,
strings, etc. Our three examples above go from most sugared (top), to least sugared (bottom).
The bottom examples above could be wrapped in curly braces, making it more obvious that it is a code
Expand All @@ -253,7 +253,7 @@ block. Note that a where clause may also take an explicit Callable.
If you read the section in this page on subsets, you'll notice that "where" is used in the making of
subsets as well as here. The usage of "where" in both areas is exactly the same.
When using `where`, note that the order of definition is important, just like in Haskell.
When using C<where>, note that the order of definition is important, just like in Haskell.
multi greeting ( Str \name where '' --> 'Hello, World!' ){}
multi greeting ( Str \name where { Bool.pick } --> 'True' ){}
Expand Down Expand Up @@ -299,15 +299,15 @@ In Perl6 you can achieve this same thing with the given/when structure:
default { "don't care" }
}
Note that the order of the `when`'s is also significant, just like with the `where`'s in the
Note that the order of the C<when>'s is also significant, just like with the C<where>'s in the
guard section of this page.
=head1 Lists
TODO
explain difference between perl6 Array, Sequence, List. Explain data shapes in regards
to the `@` sigil. Explain how you can convert an Array to a flattened list of objects with `|@`
to the C<@> sigil. Explain how you can convert an Array to a flattened list of objects with C<|@>
data shapes become quite intuitive, but it takes a bit of practice.
Expand Down Expand Up @@ -387,7 +387,7 @@ changed into one or the other.
TODO
explain how `given/when` and `with/without` and `for loops` open lexical scopes with the argument as the context.
explain how C<given/when> and C<with/without> and C<for loops> open lexical scopes with the argument as the context.
compare it to let/in and where constructs maybe?
Expand Down

0 comments on commit 5a14552

Please sign in to comment.