PasteRack.org
Paste #
63115
2019-07-03 08:38:04
Forked from paste #
21529
.
Fork
as a new paste.
Paste viewed 578 times.
Tweet
Embed:
<link type="text/css" rel="stylesheet" href="http://pasterack.org/scribble.css"/><link type="text/css" rel="stylesheet" href="http://pasterack.org/racket.css"/><link type="text/css" rel="stylesheet" href="http://fonts.googleapis.com/css?family=Droid+Sans+Mono"/><div style="font-family:'Droid Sans Mono',monospace;background-color:transparent"><ol start="0" style="font-size:70%;color:#A0A0A0"><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><a class="RktModLink" data-pltdoc="x" href="http://docs.racket-lang.org/guide/Module_Syntax.html#%28part._hash-lang%29"><span class="RktMod">#lang</span></a><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><a class="RktModLink" data-pltdoc="x" href="http://docs.racket-lang.org/ts-reference/index.html"><span class="RktSym">typed/racket</span></a><span class="RktMeta"></span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"> </span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"></span><span class="RktCmt">;;</span><span class="hspace"> </span><span class="RktCmt">how</span><span class="hspace"> </span><span class="RktCmt">to</span><span class="hspace"> </span><span class="RktCmt">define</span><span class="hspace"> </span><span class="RktCmt">a</span><span class="hspace"> </span><span class="RktCmt">default</span><span class="hspace"> </span><span class="RktCmt">parameter</span><span class="hspace"> </span><span class="RktCmt">value</span><span class="hspace"> </span><span class="RktCmt">for</span><span class="hspace"> </span><span class="RktCmt">a</span><span class="hspace"> </span><span class="RktCmt">function</span><span class="hspace"> </span><span class="RktCmt">in</span><span class="hspace"> </span><span class="RktCmt">t/r?</span><span class="RktMeta"></span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"> </span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym"><a class="RktStxLink" data-pltdoc="x" href="http://docs.racket-lang.org/ts-reference/special-forms.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._define%29%29">define</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">foo</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktPn">[</span><span class="RktSym">bar</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a class="RktStxLink" data-pltdoc="x" href="http://docs.racket-lang.org/ts-reference/special-forms.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fprims..rkt%29._~3a%29%29">:</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym"><a class="RktStxLink" data-pltdoc="x" href="http://docs.racket-lang.org/ts-reference/type-ref.html#%28form._%28%28lib._typed-racket%2Fbase-env%2Fbase-types..rkt%29._.Any%29%29">Any</a></span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">0</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="RktMeta"></span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktSym">bar</span><span class="RktPn">)</span><span class="RktMeta"></span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"> </span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">foo</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktVal">1</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktCmt">;</span><span class="hspace"> </span><span class="RktCmt">succeeds</span><span class="RktMeta"></span></span></li><li><span style="font-family:'Droid Sans Mono',monospace;font-size:125%"><span class="RktMeta"></span><span class="RktPn">(</span><span class="RktSym">foo</span><span class="RktPn">)</span><span class="RktMeta"></span><span class="hspace"> </span><span class="RktMeta"></span><span class="RktCmt">;</span><span class="hspace"> </span><span class="RktCmt">type</span><span class="hspace"> </span><span class="RktCmt">checker</span><span class="hspace"> </span><span class="RktCmt">error:</span><span class="hspace"> </span><span class="RktCmt">wrong</span><span class="hspace"> </span><span class="RktCmt">number</span><span class="hspace"> </span><span class="RktCmt">of</span><span class="hspace"> </span><span class="RktCmt">arguments!</span><span class="RktMeta"></span></span></li></ol><p>=></p><blockquote><table style="font-size:90%;table-layout:fixed;width:100%;word-wrap:break-word"><tr><td><p><span class="RktOut">- : Any</span></p></td></tr><tr><td><p><span class="RktRes">1</span></p></td></tr><tr><td><p><span class="RktOut">- : Any</span></p></td></tr><tr><td><p><span class="RktRes">0</span></p></td></tr></table></blockquote></div>
how to define a default parameter value for a function in t/r?
#lang
typed/racket
;;
how
to
define
a
default
parameter
value
for
a
function
in
t/r?
(
define
(
foo
[
bar
:
Any
0
]
)
bar
)
(
foo
1
)
;
succeeds
(
foo
)
;
type
checker
error:
wrong
number
of
arguments!
=>
- : Any
1
- : Any
0