Skip to content

Instantly share code, notes, and snippets.

@FCO
Created November 22, 2018 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FCO/b23b055ada6ef458a8c3c1d29e39aa91 to your computer and use it in GitHub Desktop.
Save FCO/b23b055ada6ef458a8c3c1d29e39aa91 to your computer and use it in GitHub Desktop.
unit class MetamodelX::Protocol is Metamodel::SubsetHOW is Metamodel::ClassHOW;
method new_type(:$name!) {
my $type;
$type := callwith :$name, :refinee(Any), :refinement{ .^methods>>.name.any eq $type.^methods>>.name.all }
$type
}
method compose(\type) {
die "A Protocol must have only stub methods!" if type.^methods.grep: not *.yada;
}
my package EXPORTHOW {
package DECLARE {
use MetamodelX::Protocol;
constant protocol = MetamodelX::Protocol;
}
}
MacBook-Pro-de-Fernando:Protocol fernando$ perl6 -Ilib -MProtocol -e '
protocol Bla { method bla { ... } }
my Bla $a = 42
'
Type check failed in assignment to $a; expected Bla but got Int (42)
in block <unit> at -e line 6
MacBook-Pro-de-Fernando:Protocol fernando$ perl6 -Ilib -MProtocol -e '
protocol Bla { method bla { ... } }
my Bla $a = class { method bla {} }.new
'
MacBook-Pro-de-Fernando:Protocol fernando$ perl6 -Ilib -MProtocol -e '
protocol Bla { method bla { ... }; method ble {} }
my Bla $a = class { method bla {} }.new
'
===SORRY!=== Error while compiling -e
A Protocol must have only stub methods!
at -e:4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment