-
-
Save timo/5c8544ec4e8166041e86 to your computer and use it in GitHub Desktop.
working on a haskell compatible algebraic datatype module for perl6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ADT; | |
package EXPORT::DEFAULT { }; | |
grammar hs_adt { | |
has @.typevars; | |
rule TOP { | |
$<name>=(<ident>) <params> '=' <definers> | |
} | |
rule params { | |
'[' ~ ']' [ '::'$<typevar>=<.ident> { @.typevars.push($0) }]+ % ',' | | |
} | |
rule parameters { | |
'[' ~ ']' [$<typevar>=<.ident> { $0 ~~ @.typevars }]+ | | |
} | |
rule definers { | |
[ <definition> ]+ % '|' | |
} | |
rule definition { | |
$<constructor>=<.ident> [ $<typedecl>=<.ident> <parameters> ]+ % ',' | |
} | |
} | |
#sub create_adt(@structure) { | |
#} | |
use Test; | |
ok hs_adt.parse("Tree = Branch Tree, Tree | Leaf Str"); | |
ok hs_adt.parse("Tree[::A] = Branch Tree[A], Tree[A] | Leaf A"); | |
ok hs_adt.parse("Either[::A, ::B] = Left A | Right B"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment