skolems icon indicating copy to clipboard operation
skolems copied to clipboard

Support for forall type constructor

Open lemastero opened this issue 6 years ago • 2 comments

I would like to write sth like this:

import skolems.∀

object Stuff {
  trait Profunctor[=>:[_, _]] {
    def dimap[S,T,A,B](sa: S => A, bt: B => T): A =>: B => S =>: T
  }

  type Optics[P[_, _],S,T,A,B] = P[A,B] => P[S,T]
  type Iso2[S,T,A,B] = ∀[λ[P => Profunctor[P] => Optics[P,S,T,A,B]]]
}

Compiler points out that P needs type arguments:

[error] P takes no type parameters, expected: two
[error]   type Iso2[S,T,A,B] = ∀[λ[P => Profunctor[P] => Optics[P,S,T,A,B]]]

If I give him some,

type Iso2[S,T,A,B] = ∀[λ[P[_,_] => Profunctor[P] => Optics[P,S,T,A,B]]]

he chokes with final words:

[error] kinds of the type arguments ([P[_$1, _$2]]Stuff.Profunctor[P] => (P[A,B] => P[S,T])) do not conform to the expected kinds of the type parameters (type F).
[error] [P[_$1, _$2]]Stuff.Profunctor[P] => (P[A,B] => P[S,T])'s type parameters do not match type F's expected parameters:
[error] type P has two type parameters, but type _ has none
[error]   type Iso2[S,T,A,B] = ∀[λ[P[_,_] => Profunctor[P] => Optics[P,S,T,A,B]]]

When I try to review him by kind projector:

type Iso2[S, T, A, B] = ∀[λ[P[*,*] => Profunctor[P] => Optics[P, S, T, A, B]]]

then it curses ⚡️ at me:

  [error] <console>:1:10: $times is already defined as type *
  [error] type _X_[*] = Unit
  [error]          ^
  [error] one error found

Maybe I am doing sth wrong 🤔 or maybe this could be a nice feature for skolems. Cheers 🍻

lemastero avatar Jan 25 '20 00:01 lemastero

It only works for type constructors with one type parameter: type ∀[+F[_]] = Forall[F], but you are trying to use it with two. The error messages are crazy though :smile:

joroKr21 avatar Jan 25 '20 07:01 joroKr21

I am playing around with idea of supporting type classes with 2 type holes: https://github.com/lemastero/skolems/pull/1

lemastero avatar Apr 22 '20 09:04 lemastero