Type expanders (i.e. type-level functions) for Typed/Racket
Go to file
Suzanne Soy 9fbbe96f97
Merge pull request #13 from capfredf/fix-types
change polymorphic types to type constructors
2021-11-11 09:24:55 +00:00
base/lang Squashed commits. 2017-04-27 22:54:34 +02:00
lang Bugfix: for some reason #lang type-expander/lang stopped to work after replacing the lang.rkt symlink, to fix #11. 2017-05-05 14:36:15 +02:00
licenses Squashed commits. 2017-04-27 22:54:34 +02:00
scribblings Changed my name :) 2021-03-04 20:38:13 +00:00
test change polymorphic types to type constructors 2021-11-05 13:39:24 -04:00
.gitignore Squashed commits. 2017-04-27 22:54:34 +02:00
.gitmodules Squashed commits. 2017-04-27 22:54:34 +02:00
.travis.yml Updated Racket versions in .travis.yml 2019-04-24 22:45:41 +02:00
base.rkt Squashed commits. 2017-04-27 22:54:34 +02:00
contracts-to-types.rkt Small improvements to contract→type 2017-05-05 03:34:17 +02:00
dbg.rkt Squashed commits. 2017-04-27 22:54:34 +02:00
expander.rkt Squashed commits. 2017-04-27 22:54:34 +02:00
identifiers.rkt Squashed commits. 2017-04-27 22:54:34 +02:00
info.rkt Changed my name :) 2021-03-04 20:38:13 +00:00
lang.rkt Fixes #1: Install fails on Windows because lang.rkt is a symbol link. 2017-05-05 14:31:57 +02:00
LICENSE Squashed commits. 2017-04-27 22:54:34 +02:00
main.rkt Squashed commits. 2017-04-27 22:54:34 +02:00
more-expanders.hl.rkt Squashed commits. 2017-04-27 22:54:34 +02:00
parameterize-lexical-context.rkt Squashed commits. 2017-04-27 22:54:34 +02:00
README.md Renamed main branch 2021-04-04 07:23:09 +01:00
type-expander.hl.rkt check tvars are ids before using free-identifier=? 2019-04-03 16:03:48 -04:00
utils.rkt Squashed commits. 2017-04-27 22:54:34 +02:00

Build Status, Coverage Status, Build Stats, Online Documentation, Maintained as of 2018.

Type-expander

This project is written for Typed/Racket using Literate Programming. See the “Implementation of the type expander library” part of the online documentation if you want to dig into the source.

This library enhances typed/racket with type expanders, which are special macros that can appear where a type would normally be expected, and must expand to a type. Type expanders are to types what match expanders are to match patterns. It is based on Asumu Takikawa's type expanders (see also his original pull request here). Asumu Takikawa's work attempted to integrate type expanders directly into Typed/Racket. This project instead implements type expanders as a library and works without any modification of the core Typed/Racket codebase. This shows the extensibility of Typed/Racket thanks to macros, and could serve as the basis for other projects which need to alter the manner in which Typed/Racket handles types.

Installation

raco pkg install --deps search-auto type-expander

Usage example

The type-expander is enabled by simply requiring the type-expander module in a typed/racket program.

#lang typed/racket
(require type-expander)

For example, one can write the (HomogeneousList n t) type-expander, which expands to the type for a list of n elements of type t:

(require (for-syntax syntax/parse racket/list))
(define-type-expander (HomogeneousList stx)
  (syntax-parse stx
    [(_ t:expr n:nat)
     #`(List #,@(map (λ (x) #'t)
                     (range (syntax-e #'n))))]))

It can then be used wherever a regular type is usually expected:

(: five-strings (→ String (HomogeneousList String 5)))
(define (five-strings x)
  (list x "a" "b" "c" "d"))

(five-strings "hello")
;; => '("hello" "a" "b" "c" "d")

(ann (five-strings "moon") (HomogeneousList String 5))
;; => '("moon"  "a" "b" "c" "d")