type-constructor

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

Difference between F[_] and F[T] In Scala when used in type constructors

↘锁芯ラ 提交于 2020-08-22 09:39:06
问题 This question is about _ as used in type constructor and not when used in defining existential types. So the question is what is the difference when _ is used as type parameter instead of a variable like T . For example difference between F[_] and F[T] . The only difference I can think of is that with F[_] the parameter itself can have as many holes as possible...that is F[_] can become F[Int] or F[Future[Option[Int]]] etc...while when you have F[T] the T can only be a proper type...that is F

Type Constructor as Return Type

 ̄綄美尐妖づ 提交于 2020-07-05 07:22:43
问题 In Scala, I can define an Algebraic Data Type: scala> sealed trait Maybe[A] defined trait Maybe scala> case class Just[A](x: A) extends Maybe[A] defined class Just scala> case object NothingHere extends Maybe[Nothing] defined object NothingHere It's possible to return a function, f , with a return type of Maybe[A] . scala> def f[A](x: A): Maybe[A] = Just(x) f: [A](x: A)Maybe[A] However, it's also possible to specify that a Just[A] is returned. scala> def f[A](x: A): Just[A] = Just(x) f: [A](x

Type Constructor as Return Type

佐手、 提交于 2020-07-05 07:21:29
问题 In Scala, I can define an Algebraic Data Type: scala> sealed trait Maybe[A] defined trait Maybe scala> case class Just[A](x: A) extends Maybe[A] defined class Just scala> case object NothingHere extends Maybe[Nothing] defined object NothingHere It's possible to return a function, f , with a return type of Maybe[A] . scala> def f[A](x: A): Maybe[A] = Just(x) f: [A](x: A)Maybe[A] However, it's also possible to specify that a Just[A] is returned. scala> def f[A](x: A): Just[A] = Just(x) f: [A](x

Underscores in type bounds on type constructors

不打扰是莪最后的温柔 提交于 2020-01-13 09:17:47
问题 Can someone explain why the following doesn't compile? I want that BB[A] is also a List[A] . The method body only enforces this view. scala> def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]} <console>:8: error: type mismatch; found : BB[A] required: List[A] def x[A, BB[_] <: List[_]](p: BB[A]) {p: List[A]} ^ 回答1: I think you need to name the _ parameter. scala> def x[A, BB[X] <: List[X]](p: BB[A]) {p: List[A]} works. 来源: https://stackoverflow.com/questions/6492934/underscores-in-type-bounds

Type Deconstruction

非 Y 不嫁゛ 提交于 2019-12-23 09:02:59
问题 My data types will always have at least two parameters, and the last two parameters are always 'q' and 'm', respectively: {-# LANGUAGE TypeFamilies, FlexibleContexts, UndecidableInstances, TypeOperators, DataKinds, ConstraintKinds, FlexibleInstances #-} data D1 q m = D1 q data D2 t q m = D2 q class Foo a where -- a has kind * -> * f :: a x -> a x class (Foo b) => Bar b where -- b has kind * -> * -- the purpose of g is to change ONE type parameter, while fixing the rest -- the intent of the

How to use a type alias to define a type constructor

烈酒焚心 提交于 2019-12-13 13:13:24
问题 Let's say I have some code that uses List def processList(input: List[Int]): List[Int] I want to replace list with other collection types, like Vector. Is there a way to define a type constructor so that I can write something like type SomeCollection[_] = List[_] def processList(input: SomeCollection[Int]): SomeCollection[Int] Now I have written processList in terms of SomeCollection. To change SomeCollection to Vector, I just change the type alias, and everywhere in the codebase where I use

Modeling a binary relationship between two types

梦想的初衷 提交于 2019-12-06 04:39:24
问题 There are businesses and people. Users can either like or post a comment about a business but the same can not happen with a person. When a user posts something about a business or likes it, that business is called the target of that like or post: trait TargetingRelation[TargetingType[_],TargetedType] class Business class Person class Post[Target | TargetingRelation[Business,Post] ] { def target:Target } class Like[Target | TargetingRelation[Business,Like] ] { def target:Target } Here I'm

Why is there a value constructor in addition to the type constructor in Haskell?

北城以北 提交于 2019-12-04 16:59:42
问题 I'm a newcomer to Haskell and am currently going through Real World Haskell. The book says the type constructor is used only in the type signature while the value constructor is used in actual code. It also gives an example of a declaration to show that the names for both are independent of each other. Why are two constructors needed in the first place, if only one of them is used in actual code? Since we would not use the type constructor in actual code, what purpose does the type

Modeling a binary relationship between two types

蓝咒 提交于 2019-12-04 09:26:31
There are businesses and people. Users can either like or post a comment about a business but the same can not happen with a person. When a user posts something about a business or likes it, that business is called the target of that like or post: trait TargetingRelation[TargetingType[_],TargetedType] class Business class Person class Post[Target | TargetingRelation[Business,Post] ] { def target:Target } class Like[Target | TargetingRelation[Business,Like] ] { def target:Target } Here I'm inventing a T | P[T] notation meaning type parameter T such that it satisfies some property P[T] (or T :|: