Questions tagged [typed-racket]

Typed Racket is a statically typed dialect of the Racket Scheme-derived language, that eases the migration from untyped to typed code.

Typed Racket is a statically typed dialect of that eases the migration from untyped to typed code.

Typed Racket is a family of languages, each of which enforce that programs written in the language obey a type system that ensures the absence of many common errors. The Typed Racket Guide is intended for programmers familiar with Racket. For an introduction to Racket, see The Racket Guide.

130 questions
15
votes
1 answer

What are the similarities and differences between the typing features in Typed Racket and the type-like features in Clojure?

Clojure has some interesting features for representing types including but not limited to deftype, defprotocol, reify and extend. What are the similarities and differences between the typing features in Typed Racket and the type-like features in…
hawkeye
  • 31,052
  • 27
  • 133
  • 271
14
votes
1 answer

How does Typed Racket's type inference work?

What kind of type inference does Typed Racket do? I found the following snippet on the Racket mailing list: The Typed Racket type system contains a number of features that go beyond what's supported in Hindley/Milner style type systems, and so …
Ord
  • 5,113
  • 4
  • 25
  • 42
12
votes
0 answers

Is a function that curries the first argument of a list of functions typeable in Typed Racket?

I can write a simple function in untyped Racket called curry-all that takes a list of functions, all of which accept the same kind of value for their first argument, and produces a list of functions with their first arguments curried. (define…
Alexis King
  • 40,717
  • 14
  • 119
  • 194
12
votes
1 answer

How can I use JSON's `jsexpr?` predicate with Typed Racket?

I'm trying to use the json package in Typed Racket, but I'm having some trouble handling how to type the jsexpr? predicate. My first attempt was simply using #:opaque. (require/typed json [#:opaque JSExpr jsexpr?]) The trouble is…
Alexis King
  • 40,717
  • 14
  • 119
  • 194
8
votes
1 answer

How do I write higher-order functions that take polymorphic functions as arguments in Typed Racket?

For example, how can I write a version of map that will work with polymorphic functions in Typed Racket? I use a simple id function defined as: (: id : (All (A) A -> A)) (define (id x) x) When I try to map it over a list i get an error: > (map id…
6
votes
1 answer

Racket enforce input types for function

I'd like to enforce the data type for input to a function in racket. For example, in this function I want to expect integers and throw an error if someone inputs a string. Is there a standard way to enforce this in Racket? (sum-coins pennies…
NDavis
  • 917
  • 1
  • 11
  • 20
6
votes
2 answers

Type Predicates for Function Types in Typed/Racket

I'm at the early stages of designing a framework and am fooling around with typed/racket. Suppose I have the following types: (define-type Calculate-with-one-number (-> Number Number)) (define-type Calculate-with-two-numbers (-> Number Number…
ben rudgers
  • 3,509
  • 2
  • 17
  • 29
5
votes
1 answer

Type mismatch issue of sub1

I can't figure out why the sub1 function in pick1 has type mismatch issue,but pick0 don't (define-predicate one? One) (: pick1 (-> Positive-Integer (Listof Any) Any)) (define pick1 (λ(n lat) (cond [(one? n) (car lat)] [else (pick1…
Lyu Yao Ting
  • 121
  • 5
5
votes
1 answer

Applying cast to dynamically required function in typed racket

I'm trying to load and use a function from a different module at run-time. The issue is that dynamic-require's range, Any, can't seem to be casted to a more specific (function) type. test.rkt: #lang typed/racket (module other-module typed/racket …
Michael MacLeod
  • 130
  • 1
  • 6
5
votes
1 answer

Why using a class from a typed/racket module in a untyped one yields bad performance?

See EDIT 1, 2, and 3 for updates. I leave here the complete research process. I know we can use typed/racket modules from untyped racket (and vice versa). But when doing so, the typed/racket module just behaves as if it was typed/racket/no-check,…
Zoé Martin
  • 1,642
  • 1
  • 15
  • 25
5
votes
1 answer

Representing the function EOF -> False, A -> A ∀ A ≠ EOF in Typed Racket?

I am trying to define the type annotation for the following function in Typed Racket: (define (neof x) (if (eof-object? x) #f x)) Leaving it un-annotated gives the type: (Any -> Any) Using this type produces an error: (: neof (All (A) (case->…
J David Smith
  • 4,510
  • 1
  • 16
  • 23
5
votes
2 answers

When to use `form:` in Typed Racket?

ts-guide said: In addition to the : form, almost all binding forms from racket have counterparts which allow the specification of types. But it does not say when to use which one. And ts-reference said form: is legacy, for backwards…
weakish
  • 23,766
  • 4
  • 44
  • 54
5
votes
2 answers

How to optimize this piece of Racket code?

I want to calculate the sum of 1 + 1/2 + 1/3 + ... + 1/100000000 (using double float). With SBCL, this code runs as fast as in C: (loop for i fixnum from 1 to 100000000 sum (/ 1.0d0 i) double-float) How can I optimize this code in Typed Racket?…
SaltyEgg
  • 1,368
  • 1
  • 10
  • 23
5
votes
1 answer

for/list annotations in typed/racket

I'm trying to add types to some numerical racket code in the hopes of making it faster, but I am stuck dealing with for/list macro expansion in the code below. (: index-member ((Listof Any) (Listof Any) -> (Listof Index))) (define (index-member xs…
wdkrnls
  • 3,946
  • 2
  • 29
  • 52
4
votes
0 answers

How could I specify a function that can accept any type exclude one type in typed/racket?

I mean, just like annotate a function as (: function (-> (Not String) String)) I know this doesn't work, is there a way to achieve it?
Eleven
  • 59
  • 5
1
2 3
8 9