Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Existential types in record constructors #172

Open
AshleyYakeley opened this issue Nov 14, 2022 · 3 comments
Open

Existential types in record constructors #172

AshleyYakeley opened this issue Nov 14, 2022 · 3 comments
Milestone

Comments

@AshleyYakeley
Copy link
Owner

AshleyYakeley commented Nov 14, 2022

Extend record constructors (#150) to have existential types and subtype relations.

  • type T - +
  • type storable T + +
  • subtype P <: Q

Examples:

datatype Machine -a +b of
    MkMachine of
    type S;
    initial: S;
    step: a -> S -> S *: b;
    end;
end

runMachine: Machine a b -> List a -> List b =
    fn MkMachine => let
        run = fn olds => match
            [] => [];
            a :: aa => let
                (news,b) = step a olds;
                bb = run news;
                in b :: bb;
            end;
        in run initial

runningSum: Machine Integer Integer =
    MkMachine of
    type S = Integer;
    initial = 0;
    step = fns a s => let b = a+s in (b,b);
    end;

Note types can have any kind:

datatype R of
    MkR of
    type S - + {-,+};
    ...
    end;
end
@AshleyYakeley AshleyYakeley added this to the 0.4 milestone Nov 14, 2022
@AshleyYakeley
Copy link
Owner Author

AshleyYakeley commented Nov 15, 2022

Type escape issue:

let

datatype R of
    MkR of
        type T
        v: T -> Action T
    end;
end;

f = fn MkR => v;

r1: R
= MkR of
    type T = Integer;
    v = fn _ => return 0;
end;

r2: R
= MkR of
    type T = Text;
    v = fn t => writeLn stdout (t <> "!") >> return t
end;

in f r1 undefined >>= f r2

f cannot be given a type. Solution: when matching a record pattern over an expression, examine the type of the expression to ensure it does not contain existential types defined in the record.

@AshleyYakeley
Copy link
Owner Author

AshleyYakeley commented Nov 18, 2022

@AshleyYakeley
Copy link
Owner Author

AshleyYakeley commented Sep 3, 2024

Idea: distinguish upper case and lower case:

type T

  • Can be any kind, e.g. type T +a -b {-c,+d}
  • No inference, must be specified by user

type t (#312)

  • kind * only
  • Doesn't need to be specified, can be inferred

record functions

rf: t of type t; f: a -> (t *: Maybe a) end

Type of rf is effectively forall t. (forall a. a -> (t *: Maybe a)) -> t

record constructors

datatype R +t of Mk of type t; f: a -> (t *: Maybe a) end end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant