syntax for a pure type system with pattern matching (12)

1 Name: #!/usr/bin/anonymous : 2009-12-02 07:24 ID:+xAynyju

I'm just wondering what you guys think of this syntax. How much can you decipher without any explanation? I posted this to 4chan's /prog/, but they were too busy achieving satori.
[code]
# This is a comment.

Nat : Type;
0 : Nat;
succ : Nat > Nat;

#!

  • : Nat > Nat > Nat
    = $0? m! m
    | $succ n? m! + n (succ m);

!#

  • m = $0? m
    | $succ n! + (succ m) n;

List : Nat > Type > Type;
nil : t < List 0 t;
cons : n < t < t > List n t > List (succ n) t;

sum : n < List n Nat > Nat

= $cons x xs? + x (sum xs)
| $nil! 0;

map : n < a < (a > a) > List n a > List n a

= f! $nil? nil
| $cons x xs! cons (f x) (map f xs);

(foldr : n < a < b < (a > b > b) > b > List n a > b)

   f z = $nil? z
| $cons x xs! f x (foldr f z xs);

(foldr1 : n < a < b < (a > b > b) > b > List (succ n) a > b)

    f z ($cons x xs) = foldr f x xs;

foldl f z = $nil? z

      | $cons x xs! foldl f (f z x) xs;

foldl1 f ($cons x xs) = foldl f x xs

Matrix : Nat > Nat > Type > Type

mkMatrix = m < n < t < List m (List n t)

mul : a < b < c < t < Matrix a b t > Matrix b c t > Matrix a c t

= #not implemented yet.

[/code]

2 Name: #!/usr/bin/anonymous : 2009-12-02 07:38 ID:t7GQhuYk

Something tells me the formatting of that code is screwed up, try again after disabling WakabaMark.

3 Name: #!/usr/bin/anonymous : 2009-12-02 08:10 ID:+xAynyju

Whoops.
`
# This is a comment.

Nat : Type;
0 : Nat;
succ : Nat > Nat;

#!

  • : Nat > Nat > Nat
    = $0? m! m
    | $succ n? m! + n (succ m);

!#

  • m = $0? m
    | $succ n! + (succ m) n;

List : Nat > Type > Type;
nil : t < List 0 t;
cons : n < t < t > List n t > List (succ n) t;

sum : n < List n Nat > Nat

= $cons x xs? + x (sum xs)
| $nil! 0;

map : n < a < (a > a) > List n a > List n a

= f! $nil? nil
| $cons x xs! cons (f x) (map f xs);

(foldr : n < a < b < (a > b > b) > b > List n a > b)

   f z = $nil? z
| $cons x xs! f x (foldr f z xs);

(foldr1 : n < a < b < (a > b > b) > b > List (succ n) a > b)

    f z ($cons x xs) = foldr f x xs;

foldl f z = $nil? z

      | $cons x xs! foldl f (f z x) xs;

foldl1 f ($cons x xs) = foldl f x xs

Matrix : Nat > Nat > Type > Type

mkMatrix = m < n < t < List m (List n t)

mul : a < b < c < t < Matrix a b t > Matrix b c t > Matrix a c t

= #not implemented.

`

4 Name: #!/usr/bin/anonymous : 2009-12-02 08:11 ID:+xAynyju

What the hell? Every line? Really?

5 Name: #!/usr/bin/anonymous : 2009-12-02 11:56 ID:Heaven

>>4
Just load your code in some buffer, and M-S-< C-x ( M-4 <space> C-x ) M-1000 C-x e

6 Name: #!/usr/bin/anonymous : 2009-12-02 15:05 ID:nTP8tNHO

I must be some sort of idiot. Here comes the third try:

<code>

# This is a comment.

Nat : Type;
0 : Nat;
succ : Nat > Nat;

#!
+ : Nat > Nat > Nat
= $0? m! m
| $succ n? m! + n (succ m);
!#

+ m = $0? m
| $succ n! + (succ m) n;

List : Nat > Type > Type;
nil : t < List 0 t;
cons : n < t < t > List n t > List (succ n) t;

sum : n < List n Nat > Nat
= $cons x xs? + x (sum xs)
| $nil! 0;

map : n < a < (a > a) > List n a > List n a
= f! $nil? nil
| $cons x xs! cons (f x) (map f xs);

(foldr : n < a < b < (a > b > b) > b > List n a > b)
f z = $nil? z
| $cons x xs! f x (foldr f z xs);

(foldr1 : n < a < b < (a > b > b) > b > List (succ n) a > b)
f z ($cons x xs) = foldr f x xs;

foldl f z = $nil? z
| $cons x xs! foldl f (f z x) xs;

foldl1 f ($cons x xs) = foldl f x xs

Matrix : Nat > Nat > Type > Type

mkMatrix = m < n < t < List m (List n t)

mul : a < b < c < t < Matrix a b t > Matrix b c t > Matrix a c t
= #not implemented.

</code>

the <code> tags aren't even necessary, are they?

7 Name: #!/usr/bin/anonymous : 2009-12-03 04:32 ID:Heaven

>>6
lurk more

8 Name: #!/usr/bin/anonymous : 2009-12-03 23:26 ID:Heaven

or simply RTFM

9 Name: #!/usr/bin/anonymous : 2009-12-04 06:43 ID:zAr9eXlJ

What's up with functional programmers and non-descriptive variable names? Fuck you guys. Learn how to write readable and maintainable code.

I'm a huge fan of referential transparency, I just hate the culture that has grown up around it.

10 Name: dmpk2k!hinhT6kz2E : 2009-12-04 09:00 ID:Heaven

Alas, I haven't read my TAPL, nor am I fan of Haskell or Agda. Having said that, I think I understood it till this point:

cons : n < t < t > List n t > List (succ n) t;

Okay, you're consing, but I don't understand what's going on with those <, and I concur with >>9's sentiment.

Also, I am not a fan of currying. It seems so clever until you realize how limited it is: one arg at a time, left to right. And then it fags > up > all > your > type > signatures. Bah.

11 Name: #!/usr/bin/anonymous : 2009-12-10 17:51 ID:bBhMUELL

What I understood from that sample is that

#! ... !#

is a multi-line comment,

n <

basically means foreach n or specifies that n is inferred,

$ ? !

are somehow used for pattern matching but I can't seem to figure out exactly how. I also can't figure out what f! does.
You also got

mkMatrix = m < n < t < List m (List n t)

and

foldr1 : n < a < b < (a > b > b) > b > List (succ n) a > b

wrong.

12 Name: KnowItAll : 2009-12-13 00:14 ID:X8s+1sbd

lame

This thread has been closed. You cannot post in this thread any longer.