Last active
February 19, 2016 01:25
-
-
Save LLFourn/9e08d3a94b08af9d5c38 to your computer and use it in GitHub Desktop.
Why I want to negate Types
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
# introspecting the return vale of a sub | |
my $return-descr = do given &foo.returns { | |
when $_ !=== Any { "the programmer has not specified the return value" } | |
when Any:D { "returns a definite" } | |
when $_ !~~ Any:D { "returns a type object" } | |
when Any { "may return either a type object or a definite"} | |
} | |
# I would prefer to use something like ¬ (returns a subset type matching anything that doesn't match it) | |
when ¬Any:U | |
when Any:D | |
when ¬Any:D | |
when Any | |
#more examples out of context | |
method parameter(Parameter:D \p --> Docbrew::Parameter:D) { | |
my %h := %( | |
orig => p, | |
type => p.type, | |
(why => .contents.join("\n") with p.WHY), | |
(default => p.default if p.default !=== Any), | |
do with p.constraints { do constraints => $_ if .elems != 1 or .[0].Str ne 'all()' }, | |
|do for <optional named> -> $attr { | |
do if p."$attr"() -> $val { | |
$attr => $val | |
} | |
} | |
); | |
Docbrew::Parameter.new(|%h); | |
} | |
method !normalize-code(Code:D $code,Str :$called-as --> Docbrew::Code:D){ | |
my $tmp = \(params => self.signature($code.signature)); | |
my %node = ( | |
orig => $code, | |
(given $code.signature.returns { if $_ !=== Any { returns => $_ } } ), | |
(:$called-as with $called-as) | |
); | |
... | |
} | |
# does it twice | |
multi trait_mod:<is>(Mu:U $class,:$schema-node!) is export(:MANDATORY) { | |
my $schema-WHO = $*GLOBALish.WHO<OO-SCHEMA>.WHO; | |
if (my $node = $schema-WHO{$class.^shortname}) !=== Any { | |
$*W.install_lexical_symbol($*UNIT,'OO-SCHEMA-ENTRY',$class.^name); | |
for $node.^parents(:local(1)) { | |
my $parent = .^load-node-class; | |
if $parent !=== Any { | |
$class.^add_parent($parent); | |
} | |
} | |
$class.^add_parent($node); | |
} else { | |
die "couldn't find {$class.^shortname} in {$schema-WHO.gist}"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
note I realised that my first example is totally bogus. It's much harder to introspect return values: