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
3
votes
1 answer

How to apply in typed/racket?

In typed/racket I have a case like [(? procedure? p ) (apply p xv*)] It will cause error: Type Checker: Function has no cases in: (apply p xv*) So I write a test case to detect the reason: #lang typed/racket (: test-match-apply-0 (-> (-> Any *…
jiamo
  • 952
  • 12
  • 26
3
votes
1 answer

How to solve the type mismatch error in this currying function?

I tried to define a polymorphic type: (define-type (listt a) (U Empty (Cons a))) (struct Empty ()) (struct (a) Cons ([v : a] [w : (listt a)])) and a currying function: ;; a better name for subst-c is subst-currying (: subst-c : (∀ (a) ((->…
izuo
  • 55
  • 4
3
votes
1 answer

Why does `filter` work with higher-order occurrence typing?

On the homepage for Racket, they show this example: #lang typed/racket ;; Using higher-order occurrence typing (define-type SrN (U String Number)) (: tog ((Listof SrN) -> String)) (define (tog l) (apply string-append (filter string? l))) (tog…
dpercy
  • 429
  • 4
  • 11
3
votes
2 answers

require/typed contract in racket fails

I've tried looking at the docs but i can't find an example that i can use for my case. I need to import break from srfi/1. Here's my attempt. The example works in #lang racket. #lang typed/racket (require/typed (only-in srfi/1 break) …
KRC
  • 318
  • 2
  • 16
3
votes
1 answer

Writing the Y combinator in typed/racket

Let's say I have an untyped implementation of the Y combinator in Racket. pasterack.org version #lang racket (define Y ((λ (f) (f f)) (λ (z) (λ (f) (f (λ (x) (((z z) f) x))))))) (define factorial (Y (λ…
Suzanne Soy
  • 2,522
  • 5
  • 32
  • 48
3
votes
1 answer

How to make Typed Racket's type checker faster?

Racket is fast. But when I use Typed Racket and run the code , I find that the type checker is slow. For example , run this code from The Typed Racket Guide #lang typed/racket (struct: pt ([x : Real] [y : Real])) (: distance (-> pt pt…
baozii
  • 33
  • 2
3
votes
1 answer

Simple Typed Racket program doesn't type-check

I'm a rank beginner with Typed Racket, and I was playing around with the very simple Tree type defined in the Beginner's Guide: #lang typed/racket (define-type Tree (U leaf node)) (struct: leaf ([val : Number])) (struct: node ([left : Tree] [right :…
Pillsy
  • 9,461
  • 38
  • 68
3
votes
1 answer

Why doesn't this regexp-replace work?

according to this, the regular expression \W+([.:,.!?;])(.) with the substitution group $1 $2 does exactly what I want--reduces runs of whitespace and punctuation to the final punctuation mark, a space, then picks up where it was. For my purposes,…
Ben
  • 4,521
  • 2
  • 37
  • 73
3
votes
2 answers

How do I create a "probability" HOF (or syntax) in typed racket

I am trying to create an HOF in typed racket which will allow me to express the idea, "at evaluation time, roll the dice and pick the procedure to apply". Currently, I am working with the following: (: odds-on ((Any * -> Any) (Any * -> Any) Real…
Ben
  • 4,521
  • 2
  • 37
  • 73
3
votes
1 answer

What is the type of a variadic function in Typed Racket?

I'm attempting to convert a Racket program that uses the f32vector from ffi/vector into a Typed Racket program, which requires providing annotations for f32vector via require/typed. f32vector is however variadic; it can take a variable number of…
LogicChains
  • 3,852
  • 2
  • 13
  • 21
3
votes
1 answer

Typed Racket: Creating generic types with define-type

I'm trying to get a bit into Typed Racket, but I'm having some trouble getting an (admittedly rather constructed) experiment to work. This is what I originally had: #lang typed/racket (: generate-list (All (A) ((A -> A) (Integer -> A) Integer…
cronotk
  • 139
  • 8
2
votes
2 answers

Casting to arbitrary type in Typed Racket folding a Tree

I'm trying to produce a typed Racket procedure that for some type A, takes a Tree, and a function from two As to an A, another parameter of type A, and returns a value of type A. I'm not very familiar with the (All) syntax, but I tried using it.…
2
votes
0 answers

How do I run Pie (from The Little Typer) from the command line?

I've been reading The Little Typer for a while now and I want to actually try out Pie now instead of just reading about it. Here are the steps in which I tried to get a Pie REPL up and running in the command line (on a Mac): brew install racket raco…
Caspian Ahlberg
  • 976
  • 4
  • 12
2
votes
0 answers

Match Hash Tables in Typed Racket

I'm trying to match against a hash table in typed racket, but I keep getting the following error. The code works fine in untyped racket and I've tried changing it up some to no effect. The error looks like it's happening somewhere after the match…
2
votes
1 answer

Racket Generic Graph Library in Typed Racket

I'm trying to use the generic graph library in typed racket, by importing it with require/typed, but I keep getting these weird long errors. Has anyone managed to get the type checker to cooperate with the generic graph library? #lang…
1 2
3
8 9