Skip to content

[Experimental] Minimal support for universally quantified values.#44

Closed
TomasMikula wants to merge 1 commit intotypelevel:masterfrom
TomasMikula:forall
Closed

[Experimental] Minimal support for universally quantified values.#44
TomasMikula wants to merge 1 commit intotypelevel:masterfrom
TomasMikula:forall

Conversation

@TomasMikula
Copy link
Copy Markdown
Collaborator

In type position,

[A => F[A]]

is rewritten to structural type

{ def apply[A](): F[A] }

In term position,

[A => F[A]](fa)

is rewritten to

new { def apply[A](): F[A] = fa }

Example

val right = [A => Either[A, Int]](Right(42))
val e: Either[String, Int] = right[String]

See more examples in tests.

Shortcomings / TODOs

Reflection (structural types)

Invocation of a method on a structural type uses reflection.

Defining a supertype like

trait ForAll[F[_]] {
  def apply[A](): F[A]
}

would restrict the type constructors to the kind * -> *, so I went with structural types. Ideas on how to both support arbitrary kinds and avoid reflection are welcome.

Nested s

Nested s don't work yet:

type Exists[F[_]] = [B => [A => F[A] => B] => B]

gives not found: type ∀ for the inner .

Syntax

It would be nice if instead of

[A => List[A]]

one could write

[List]

It is unlikely this will be made possible, since information about List's type parameters is absent in this syntax tree.

I can imagine this to be supported instead:

[List[?]]

@paulp
Copy link
Copy Markdown
Contributor

paulp commented Dec 17, 2016

Forall1, Forall2, etc is better than structural types. I think structural types are a non-starter.

@TomasMikula
Copy link
Copy Markdown
Collaborator Author

Closing in favor of #54.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants