[racket] ":" preferred to "define:"?

1 view
Skip to first unread message

Neil Van Dyke

unread,
Dec 22, 2010, 12:36:48 PM12/22/10
to Racket Users List
Why is ":" preferred to "define:", when usually you're just going to
follow the ":" form with a "define" form?

The Typed Racket Reference says:

> In most cases, use of ":" is preferred to use of "define:".

--
http://www.neilvandyke.org/
_________________________________________________
For list-related administrative tasks:
http://lists.racket-lang.org/listinfo/users

Sam Tobin-Hochstadt

unread,
Dec 22, 2010, 12:40:11 PM12/22/10
to Neil Van Dyke, Racket Users List
On Wed, Dec 22, 2010 at 12:36 PM, Neil Van Dyke <ne...@neilvandyke.org> wrote:
> Why is ":" preferred to "define:", when usually you're just going to follow
> the ":" form with a "define" form?
>
> The Typed Racket Reference says:
>
>> In most cases, use of ":" is preferred to use of "define:".

Two reasons:

1. Adding `:' before the definition allows you not to change the
existing untyped definition. This is good for diffs, for example.
2. I greatly prefer the visual appearance using `:' -- `define:'
results in lots of syntactic noise. Similarly, I prefer Haskell-style
type annotation to ML-style in those languages.

--
sam th
sa...@ccs.neu.edu

Eli Barzilay

unread,
Dec 22, 2010, 1:22:55 PM12/22/10
to Sam Tobin-Hochstadt, Racket Users List, Neil Van Dyke
40 minutes ago, Sam Tobin-Hochstadt wrote:
> On Wed, Dec 22, 2010 at 12:36 PM, Neil Van Dyke <ne...@neilvandyke.org> wrote:
> > Why is ":" preferred to "define:", when usually you're just going to follow
> > the ":" form with a "define" form?
> >
> > The Typed Racket Reference says:
> >
> >> In most cases, use of ":" is preferred to use of "define:".
>
> Two reasons:
>
> 1. Adding `:' before the definition allows you not to change the
> existing untyped definition. This is good for diffs, for example.

In my course I had a ton of definitions that were very formal but
still in comments:

;; foo : Number -> Number

and switching everything to TS was very easy with the `:' forms.

It goes the other way too -- it's much easier to move code back into
the untyped world by commenting out the `:' forms.

--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!

Reply all
Reply to author
Forward
0 new messages