higher-kinded-types

How do I make a structure generic in Rust without higher kinded type (HKT) support?

让人想犯罪 __ 提交于 2021-02-08 17:38:58
问题 I am trying to make the Iteratee structure generic so I can pass in a different parsing function and get an different Iteratee . This is the non-generic version that works: use std::io::{BufRead, BufReader}; use std::str::{from_utf8, Utf8Error}; #[derive(PartialEq, Debug)] struct Cat<'a> { name: &'a str, } fn parse<'a>(slice: &'a [u8]) -> Result<Cat<'a>, Utf8Error> { from_utf8(slice).map(|name| Cat { name: name }) } struct Iteratee<R> where R: BufRead + Sized { read: R, } impl<R> Iteratee<R>

Is there a shorthand for type variable 'm forSome { type m[O] <: UpperBound[O] }` in Scala?

﹥>﹥吖頭↗ 提交于 2021-02-05 08:09:30
问题 Problem: trait UpperBound[O] trait High[F[O] <: UpperBound[O]] def canEqual(that :Any) = that.isInstanceOf[High[_]] def high(h :High[_]) = ??? Does not compile, because scalac sees the _ type instead of a type constructor it expects. How to fix it, ideally without writing a novel? Original question (before edits in reply to Dmytro's answer) had: def canEqual(that :Any) = that.isInstanceOf[High[m forSome { type m[O] <: UpperBound[O] }]] def high(h :High[m forSome { type m[O] <: UpperBound[O] }

Difference between [A: C] and [A[_]: C] context bounds

眉间皱痕 提交于 2021-01-29 22:00:38
问题 I'm a newbie, according to my lectures : class Test [T: Comparing] means that it requires an implicit value of type Comparing[T] that can be used in the methods of that class. With this Higher kinded type notation Question : What does this expression def notation[F[_]: Sync] : F[Unit] = ??? refer to ? 回答1: Consider the difference between concrete type and type constructor Int // concrete type List[Int] // concrete type List // type constructor We represent the shape of the type constructor

Is it possible to enforce a type constraint on a class instance for a higher-kinded type?

人盡茶涼 提交于 2021-01-27 15:00:19
问题 I have a type defined like this: newtype PrimeSet a = P Integer deriving Eq I have also defined a function which converts a prime set to a list, given that its type parameter is an Integral . toList :: Integral a => PrimeSet a -> [a] I now what to give PrimeSet a Foldable instance, so this was my first attempt (after importing fold from Data.Foldable ): instance Foldable PrimeSet where foldMap f = fold . map f . toList This didn't work, however, and the compiler told me that it Could not

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

岁酱吖の 提交于 2020-12-29 05:54:43
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

拜拜、爱过 提交于 2020-12-29 05:53:47
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Is there an intrinsic reason explaining why Rust does not have higher-kinded-types?

帅比萌擦擦* 提交于 2020-12-29 05:53:28
问题 Rust does not have higher-kinded-types. For example, functor (and thus monad) cannot be written in Rust. I would like to know if there is a deep reason explaining this and why. For instance, reason that I can understand can be that there is no zero-cost abstraction making HKT possible. Or type inference is significantly more difficult. And of course, I also looking for an explaination showing me why this is a real limitation. If the anwer was already given somewhere else, could you give me

Can a trait have a supertrait that is parameterized by a generic?

倖福魔咒の 提交于 2020-12-26 08:32:28
问题 Can you do something like this in Rust? trait A : forall<T> B<T> { ... } That is, if we want: impl A for D { ... } We must first implement: impl<T> B<T> for D { ... } 回答1: No. Rust's type system doesn't currently support any features involving higher kinded types. It does, however, support a similar construction to what you described, but limited to lifetime parameters. For example: trait B<'a> {} trait A: for<'a> B<'a> {} struct D; impl A for D { } This is an error: error[E0277]: the trait