implement{}
print_rps (x) = let val s = case x of
| r_rps => "Rock"
| p_rps => "Paper"
| s_rps => "Scissors"
in
print_string s
end
However the compiler can’t identify the rps value.
$ patscc main.dats -DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats: 95(line=6, offs=5)
-- 111(line=6, offs=21): error(3): this pattern match clause is
redundant.
/home/kiwamu/src/practice-ats/static_rps/rps.dats: 116(line=7, offs=5)
-- 135(line=7, offs=24): error(3): this pattern match clause is
redundant.
‘true’ and ‘false’ are constants. They are treated specially when
used as patterns.
That’s naughty! Here’s what I did:
Felix originally copied Ocaml in having constant (no argument)
constructors. However I hate Camelcase. So I made the user do this:
| Fred ?argument => …
| Joe => …
This is ugly, having to put ? before variables.
So I changed it. I copied ATS No constant constructors:
| Fred argument => …
| Joe () => …
Felix always had an abbreviation in expressions:
#f ==> f ()
Its a shorthand which is very useful because in Felix type classes
you cannot have constants, only functions. So you have to do
#zero[double]
for example, for the real number class zero, instance double.
Hence:
match … with
| #True => …
| #False => …
In fact the parser translates true and false, they’re treated “special”
in the parser NOT in pattern matches. Having special things in core
parts of the compiler add complexity.
implement{}
print_rps (x) = let val s = case x of
| r_rps => "Rock"
| p_rps => "Paper"
| s_rps => "Scissors"
in
print_string s
end
However the compiler can’t identify the rps value.
$ patscc main.dats -DATS_MEMALLOC_LIBC
/home/kiwamu/src/practice-ats/static_rps/rps.dats: 95(line=6, offs=5)
-- 111(line=6, offs=21): error(3): this pattern match clause is
redundant.
/home/kiwamu/src/practice-ats/static_rps/rps.dats: 116(line=7, offs=5)
-- 135(line=7, offs=24): error(3): this pattern match clause is
redundant.
You can. You just cannot use them (r_rps, p_rps, s_rps)
as patterns. Note that ‘true’ and ‘false’ are treated specially when
used as patterns.On Saturday, October 24, 2015 at 9:32:32 AM UTC-4, Kiwamu Okabe wrote:
Hi Hongwei,
On Sat, Oct 24, 2015 at 10:22 PM, Kiwamu Okabe <kiw…@debian.or.jp <javascript:>> wrote:
‘true’ and ‘false’ are pre-defined constants?
I can’t find the definition in prelude?
‘true’ and ‘false’ are constants. They are treated specially when
used as patterns.On Saturday, October 24, 2015 at 8:58:22 AM UTC-4, Kiwamu Okabe wrote:
Hi Hongwei,
On Sat, Oct 24, 2015 at 9:34 PM, gmhwxi <gmh...@gmail.com <javascript:>> wrote:
r_rps is not a constructor and thus cannot be used as a pattern
(the compiler treats it as a variable that matches any value)
The special treatment is kind of a vestige.
One can now implement bool as a datatype
while keeping the keywords ‘true’ and ‘false’
compatible with the 1/0 interpretation:
(* ****** ****** *)
//
// False is ahead of True because
// of the need to map False to 0 and True to 1
/
datatype
bool(bool) =
| False(false) | True(true)
typedef bool = [b:bool] bool(b)
(* ****** ****** *)
#define true True() #define false False()
(* ****** ****** *)
//
fun
print_bool
(x: bool): void =
case+ x of
| true => print “true”
| false => print “false”
//
(* ****** ****** *)On Saturday, October 24, 2015 at 2:54:37 PM UTC-4, John Skaller wrote:
On 25 Oct 2015, at 00:07, gmhwxi <gmh...@gmail.com <javascript:>> wrote:
‘true’ and ‘false’ are constants. They are treated specially when
used as patterns.
That’s naughty! Here’s what I did:
Felix originally copied Ocaml in having constant (no argument)
constructors. However I hate Camelcase. So I made the user do this:
| Fred ?argument => …
| Joe => …
This is ugly, having to put ? before variables.
So I changed it. I copied ATS No constant constructors:
| Fred argument => …
| Joe () => …
Felix always had an abbreviation in expressions:
#f ==> f ()
Its a shorthand which is very useful because in Felix type classes
you cannot have constants, only functions. So you have to do
#zero[double]
for example, for the real number class zero, instance double.
Hence:
match .. with
| #True => …
| #False => …
In fact the parser translates true and false, they’re treated “special”
in the parser NOT in pattern matches. Having special things in core
parts of the compiler add complexity.