Email list hosting service & mailing list manager

Type strategy for Scheme Lassi Kortela (09 Nov 2022 22:54 UTC)
Re: Type strategy for Scheme Marc Nieper-Wißkirchen (10 Nov 2022 07:07 UTC)
Re: Type strategy for Scheme Marc Nieper-Wißkirchen (10 Nov 2022 07:42 UTC)
Re: Type strategy for Scheme Peter Bex (10 Nov 2022 08:05 UTC)
Re: Type strategy for Scheme Philip McGrath (10 Nov 2022 08:54 UTC)
Re: Type strategy for Scheme Lassi Kortela (10 Nov 2022 09:49 UTC)
Re: Type strategy for Scheme Lassi Kortela (10 Nov 2022 09:08 UTC)
Re: Type strategy for Scheme Marc Feeley (10 Nov 2022 23:34 UTC)
Re: Type strategy for Scheme Lassi Kortela (11 Nov 2022 19:17 UTC)
Re: Type strategy for Scheme Marc Feeley (11 Nov 2022 21:34 UTC)
Re: Type strategy for Scheme Lassi Kortela (12 Nov 2022 21:58 UTC)
Re: Type strategy for Scheme Marc Nieper-Wißkirchen (12 Nov 2022 22:52 UTC)
Re: Type strategy for Scheme Lassi Kortela (12 Nov 2022 23:14 UTC)
Re: Type strategy for Scheme Marc Nieper-Wißkirchen (13 Nov 2022 09:41 UTC)
Re: Type strategy for Scheme Lassi Kortela (13 Nov 2022 11:59 UTC)
Re: Type strategy for Scheme John Cowan (13 Nov 2022 19:52 UTC)
Re: Type strategy for Scheme Lassi Kortela (13 Nov 2022 20:22 UTC)
Re: Type strategy for Scheme Marc Nieper-Wißkirchen (13 Nov 2022 20:35 UTC)
Re: Type strategy for Scheme Lassi Kortela (13 Nov 2022 21:41 UTC)
Re: Type strategy for Scheme Marc Feeley (14 Nov 2022 00:03 UTC)
Re: Type strategy for Scheme Lassi Kortela (14 Nov 2022 09:36 UTC)
Re: Type strategy for Scheme Marc Feeley (14 Nov 2022 16:27 UTC)
Re: Type strategy for Scheme Lassi Kortela (14 Nov 2022 19:58 UTC)
Re: Type strategy for Scheme John Cowan (13 Nov 2022 20:40 UTC)
Re: Type strategy for Scheme Marc Nieper-Wißkirchen (13 Nov 2022 20:42 UTC)
Re: Type strategy for Scheme Panicz Maciej Godek (20 Nov 2022 21:59 UTC)
Re: Type strategy for Scheme Per Bothner (20 Nov 2022 22:58 UTC)

Re: Type strategy for Scheme Lassi Kortela 10 Nov 2022 09:08 UTC

> Starting by trying to describe types for what's already in Scheme
> sounds like a good idea.  I would start with the basics:
>
> Be creative and try to think of what should be the types of the
> following expressions:

Great! You're using exactly the kind of approach I had in mind.

> +

In a Hindley-Milner style system, where we don't have varargs, this
should be two procedures:

(unary+ z)
(binary+ z z)

and a macro:

(+ z ...)

With three or more arguments, the macro folds into calls to binary+.

Similar approach works for *, append, vector-append, string-append, etc.

- and / can use this too, but the zero-arg version may not make sense.

> 0

I suggest:

0 : integer (or fixnum?)
(expt 2 64) : integer (or bignum?)
0.0 : real
xxxxxx@0 : complex

> #i0

real (does any current Scheme implementation support inexact integers?)

> (<operator> <operand> ...)

A vararg procedure? AFAICT the vararg case has to be a macro in H-M.

Haskell can emulate varargs using typeclass magic:
https://wiki.haskell.org/Varargs

Racket uses:

(* z ...) → number?
where z : number?

> (<keyword> <datum> ...)

I.e. macro? The macro layer can use dynamically typed Scheme, or a
statically typed language where SchemeDatum is an implementation-defined
type covering all permitted datum types.

> call/cc

No idea. Maybe calling a continuation can be treated as an effect, and
hence the result has unit type?

> (lambda (x)
>    "converts seconds to minutes"
>    (/ x 60))

The "60" would coerce this into the integer version of / probably.

> (raise (make-assertion-violation))

Effect, so unit type.

> (case-lambda
>    [() 42]
>    [(x) (when (symbol=? 'x 'german) "zweiundvierzig"])

Either

(define-syntax my-thing
   (syntax-rules ()
     ((my-thing)
      42)
     ((my-thing x)
      (if (symbol=? x 'german)
          (just "zweiundvierzig")
          (nothing)))))

or

(define-union-type integer-or-string
   (the-integer integer)
   (the-string string))

(lambda (x)
   (match x
     ((nothing)
      (just (the-integer 42)))
     ((just x)
      (if (symbol=? x 'german)
          (just (the-string "zweiundvierzig"))
          (nothing)))))

> (let* ()
>    (define-record-type pair (fields x y))
>    make-pair)

(define-type-alias (pair 'a 'b)
   (record (x 'a)
           (y 'b)))

make-pair : (-> 'a 'b (pair 'a 'b))

> (values 1 2 3)

(values integer integer integer)

> values

Multiple values should probably be a tuple in H-M. values cannot be a
procedure in H-M, it has to be syntax.

> "string"

string

Note that string can be an abstract data type which is either an opaque
primitive type or (vector 'char).

> (string-copy "string")

(-> string string) when the effect is not part of the type.