polymorphic-functions

Can shapeless Record type be used as a Poly1?

纵饮孤独 提交于 2021-02-11 12:22:03
问题 Assuming if I have the following Record typed data, and a hlist of keys: val rr = ("a" ->> 1) :: ("b" -> "s") :: ("c" -> 3) :: HNil val hh = "c" :: "b" :: HNil And I want to extract values in rr for each key in hh , then combine them into a type level object, eventually yielding: (3: Int) :: ("s": String) :: HNil How this can be achieved with least amount of code? I could obviously write a inductively-summoned implicit function but it seems to be overkill 回答1: Firstly, you have typos. ->>

Can shapeless Record type be used as a Poly1?

限于喜欢 提交于 2021-02-11 12:21:58
问题 Assuming if I have the following Record typed data, and a hlist of keys: val rr = ("a" ->> 1) :: ("b" -> "s") :: ("c" -> 3) :: HNil val hh = "c" :: "b" :: HNil And I want to extract values in rr for each key in hh , then combine them into a type level object, eventually yielding: (3: Int) :: ("s": String) :: HNil How this can be achieved with least amount of code? I could obviously write a inductively-summoned implicit function but it seems to be overkill 回答1: Firstly, you have typos. ->>

Type lambda with higher kind

限于喜欢 提交于 2021-01-28 06:09:37
问题 In Dotty given the following: object Domain { final case class Create(name: String) extends BaseCreate[Create] { override type Model = Domain override def service[F[_]](client: KeystoneClient[F]): CrudService[F, Domain, Create] = client.domains } } case class Domain(id: String) class CrudService[F[_], Model, Create] final class Domains[F[_]] extends CrudService[F, Domain, Domain.Create] class KeystoneClient[F[_]] { val domains = new Domains[F] } trait BaseCreate[Create <: BaseCreate[Create]]

Can I print in Haskell the type of a polymorphic function as it would become if I passed to it an entity of a concrete type? [duplicate]

喜欢而已 提交于 2020-12-12 05:39:42
问题 This question already has answers here : Unifying c -> a -> b and (a -> b) -> c (3 answers) Closed 35 mins ago . Here's a function polymorphic in 3 types: :t (.) (.) :: (b -> c) -> (a -> b) -> a -> c and here a non polymorphic function: :t Data.Char.digitToInt Data.Char.digitToInt :: Char -> Int If we apply the former to the latter, we get a function polymorphic in 1 type: :t (.) Data.Char.digitToInt (.) Data.Char.digitToInt :: (a -> Char) -> a -> Int which means that (.) was "instantiated"

How do I write higher-order functions that take polymorphic functions as arguments in Typed Racket?

走远了吗. 提交于 2019-12-09 15:57:04
问题 For example, how can I write a version of map that will work with polymorphic functions in Typed Racket? I use a simple id function defined as: (: id : (All (A) A -> A)) (define (id x) x) When I try to map it over a list i get an error: > (map id '(1 2 3)) Type Checker: Polymorphic function `map' could not be applied to arguments: Types: (-> a b ... b c) (Listof a) (Listof b) ... b -> (Listof c) (-> a c) (Pairof a (Listof a)) -> (Pairof c (Listof c)) Arguments: (All (A) (-> A A)) (List One

How do I write higher-order functions that take polymorphic functions as arguments in Typed Racket?

落爺英雄遲暮 提交于 2019-12-04 03:11:34
For example, how can I write a version of map that will work with polymorphic functions in Typed Racket? I use a simple id function defined as: (: id : (All (A) A -> A)) (define (id x) x) When I try to map it over a list i get an error: > (map id '(1 2 3)) Type Checker: Polymorphic function `map' could not be applied to arguments: Types: (-> a b ... b c) (Listof a) (Listof b) ... b -> (Listof c) (-> a c) (Pairof a (Listof a)) -> (Pairof c (Listof c)) Arguments: (All (A) (-> A A)) (List One Positive-Byte Positive-Byte) Expected result: AnyValues in: (map id (quote (1 2 3))) You have to manually

Dynamically parametrize Poly1 function in shapeless

岁酱吖の 提交于 2019-11-27 03:31:16
问题 I have this situation (stripped down to the essential parts) class Foo[L <: HList](columns: L) { class toRecord(row: Row) extends Poly1 { implicit def caseColumn[T] = at[Column[T]] { /* map to a record field */ } } def asRecord = { val resultSet: Stream[Row] = // computation to get result set resultSet.map { row => val m = new toRecord(row) // this can't work columns.map(m) } } } This doesn't work since map wants a stable identifier and m is not. So I would need as many Poly1 singleton