Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Returning quantified types from type functions is mighty fragile #219

Open
plt-amy opened this issue Nov 11, 2019 · 6 comments
Open

Returning quantified types from type functions is mighty fragile #219

plt-amy opened this issue Nov 11, 2019 · 6 comments
Assignees
Labels
bug TC: Type Functions Issues/PRs relating to top-level closed type functions TC Issues/PRs relating to something else in the TC

Comments

@plt-amy
Copy link
Member

plt-amy commented Nov 11, 2019

type function foo ('x : bool) begin
  foo true  = forall 'a. 'a -> 'a
  foo false = ()
end

type sbool 'x =
  | STrue  : sbool true
  | SFalse : sbool false

let
  foo :
    forall 'b. sbool 'b -> foo 'b -> ()
  =
    fun x y ->
      match x with
      | STrue -> y @unit ()
      | SFalse -> y

It is reasonable to expect this would type check, but no.

@plt-amy
Copy link
Member Author

plt-amy commented Nov 11, 2019

Also doesn't work:

-       | STrue -> y @unit ()
+       | STrue -> y ()

Error:

test.ml[16:18 ..16:21]: error (E2001)
   │ 
16 │       | STrue -> y ()
   │                  ^^^^
  Couldn't match actual type forall 'a. 'a -> 'a
    with the type expected by the context, unit -> 'wge

  • Did you apply a function to too many arguments?
  • Note: 
      Where the type,
        forall 'a. 'a -> 'a,
      is the reduction of
        foo 'b

@plt-amy
Copy link
Member Author

plt-amy commented Nov 11, 2019

Also doesn't work:

-      | STrue -> y @unit ()
+      | STrue -> (y : forall 'a. 'a -> 'a) @unit ()

Error:

test.ml[16:19 ..16:19]: error (E2001)
   │ 
16 │       | STrue -> (y : forall 'a. 'a -> 'a) @unit ()
   │                   ^
  Couldn't match actual type forall 'a. 'a -> 'a
    with the type expected by the context, 'a -> 'a

  • Did you apply a function to too many arguments?
  • Note: 
      Where the type,
        forall 'a. 'a -> 'a,
      is the reduction of
        foo 'b

@SquidDev SquidDev added bug TC Issues/PRs relating to something else in the TC TC: Type Functions Issues/PRs relating to top-level closed type functions labels Nov 11, 2019
@plt-amy
Copy link
Member Author

plt-amy commented Nov 11, 2019

This rephrasing of the program works:

let
  foo :
    forall 'b. sbool 'b -> foo 'b -> ()
  =
    function
      | STrue -> fun (y : forall 'a. 'a -> 'a) -> y ()
      | SFalse -> fun y -> y

@plt-amy
Copy link
Member Author

plt-amy commented Nov 11, 2019

@plt-amy
Copy link
Member Author

plt-amy commented Nov 11, 2019

Problem with the possible solution: Core has no dependent types lol

@plt-amy
Copy link
Member Author

plt-amy commented Nov 11, 2019

What I am going to do is write a warning for this

plt-amy pushed a commit that referenced this issue Nov 11, 2019
plt-amy pushed a commit that referenced this issue Jan 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug TC: Type Functions Issues/PRs relating to top-level closed type functions TC Issues/PRs relating to something else in the TC
Projects
None yet
Development

No branches or pull requests

2 participants