marc0der
03/14/2020, 11:09 AMtrait Parsers[ParseError, Parser[+_]] {
def run[A](p: Parser[A])(input: String): Either[ParseError, A]
def char(c: Char): Parser[Char]
}
The problem of course comes when declaring the type constructor Parser[+_]
, and when you subsequently try to use a Parser
without the type constructor present, we get an error on the char
parser declaration to the effect of "_type arguments not allowed for type parameters"_. I was hoping that I could use Kind
to solve this problem but not sure how to go about it. Any help would be greatly appreciated!aballano
03/14/2020, 12:21 PMaballano
03/14/2020, 12:22 PMaballano
03/14/2020, 12:22 PMobject ParseError
class ForParser private constructor() {
companion object
}
@Suppress("UNCHECKED_CAST", "NOTHING_TO_INLINE")
inline fun <A> ParserOf<A>.fix(): Parser<A> =
this as Parser<A>
typealias ParserOf<A> = arrow.Kind<ForParser, A>
class Parser<A> : ParserOf<A> {
}
interface Parsers {
fun <A> run(p: Parser<A>, input: String): Either<ParseError, A>
fun char(c: Char): Parser<Char>
}
aballano
03/14/2020, 12:23 PMmarc0der
03/14/2020, 12:24 PMmarc0der
03/14/2020, 12:24 PMmarc0der
03/14/2020, 12:24 PMaballano
03/14/2020, 12:25 PMaballano
03/14/2020, 12:25 PMmarc0der
03/14/2020, 12:26 PMaballano
03/14/2020, 12:26 PMmarc0der
03/14/2020, 12:26 PMmarc0der
03/14/2020, 12:26 PMaballano
03/14/2020, 12:27 PMraulraja
03/14/2020, 12:27 PMraulraja
03/14/2020, 12:28 PMJannis
03/14/2020, 12:29 PMJannis
03/14/2020, 12:29 PMJannis
03/14/2020, 12:33 PMmarc0der
03/14/2020, 2:01 PMParsers
with Parser
yet in your example code so as to give us the equivalent of trait Parsers[ParseError, Parser[+_]]
in the Scala variant.pakoito
03/14/2020, 2:04 PMinterface Parser<A> : ParserOf<A>
interface Parsers<ParseError> {
fun <A> run(p: ParserOf<out A>, input: String): Either<ParseError, A>
fun char(c: Char): Parser<out Char>
}
pakoito
03/14/2020, 2:04 PMpakoito
03/14/2020, 2:05 PMpakoito
03/14/2020, 2:06 PMmarc0der
03/14/2020, 3:06 PMpakoito
03/14/2020, 5:11 PMpakoito
03/14/2020, 5:11 PMfun char(c: Char): Parser<out Char>
in this position it’s invariantkartoffelsup
03/14/2020, 6:31 PM