type-level-computation Questions
1
Solved
Is there any way to write a type family that sometimes evaluates to a constrained type such as C a => T?
This question arose when I was writing the following type family:
type family Function (c...
Solifluction asked 19/8, 2023 at 6:6
1
If I have an arbitrary type union in Scala 3, is it possible to write a method that "removes" one type from the union?
Similar to shapeless.ops.coproduct.Remove, but for native Scala 3.
F...
Herrle asked 3/7, 2022 at 16:33
1
Solved
How can I impletement type-level operations (addition in this case) in Scala 3 ?
Here is what I would like to do (this does not compile) :
case class foo[S <: Int & Singleton](value: Double)...
Tektite asked 17/3, 2023 at 10:4
1
Solved
Wanted to implement type safe matrix multiplication in Haskell.
Defined the following:
{-# LANGUAGE TypeFamilies, DataKinds, GADTs #-}
module Vector where
data Nat = Succ Nat | Zero
data Vector (...
Featherston asked 17/2, 2022 at 13:58
0
Given:
abstract class Quantity[A <: Quantity[A]]
sealed trait UnitOfMeasure[A]
class Time extends Quantity[Time]
object Minutes extends UnitOfMeasure[Time]
class PowerRamp extends Quantity[Pow...
Mewl asked 22/8, 2021 at 1:51
2
Solved
How would I go about deriving the function
getField :: (Generic a, HasDatatypeInfo a) => Proxy (name :: Symbol) -> a -> b
to project a field from an arbitrary record using a type-level st...
Bourges asked 7/4, 2021 at 18:41
1
I would like to get GHC to infer a constraint past a GADT pattern match. For instance, suppose I have two expressions, each with an inferred constraint:
f :: _ => a
g :: _ => a
(In my use ca...
Uniat asked 17/12, 2020 at 9:57
2
Solved
I have a trait Foo[T, U] and a type-level algorithm that given an L <: HList and a target type U, tells me whether there exists T in L such that there is an implicit Foo[T, U] in scope. This is ...
Banas asked 13/8, 2019 at 17:0
3
Solved
type a = [1,2,3]
type Invert<T extends any[] & {'0': any}> = ???
type b = Invert<a> // should yield [3,2,1]
I am stucked to figure out the definition of Invert type of a tuple,
al...
Triplenerved asked 9/1, 2020 at 6:47
1
I'd like to do something similar to below with labelled tuples and wondering it this posible in TS4 yet
type stringProperties<T extends {}> = {[k in keyof T]: string}
This would mean that I ...
Marius asked 3/10, 2020 at 21:51
2
Solved
I create a lot of data processing pipelines using mass spectrometry data, where data from the instrument gets cleaned up, transformed, scaled, inspected, and finally analyzed. I tend to use a recur...
Kesha asked 31/8, 2020 at 16:13
1
Solved
I'm trying to implement Conway's surreal numbers in Scala. A surreal number is defined recursively – as a pair of sets of surreal numbers, called left and right, such that no element in the right s...
Compressive asked 26/6, 2020 at 8:13
1
Solved
A nice true fact about concatenation is that if I know any two variables in the equation:
a ++ b = c
Then I know the third.
I would like to capture this idea in my own concat so I use a functio...
Serrulation asked 27/12, 2019 at 4:8
1
I'm trying to understand singleton types in shapeless and faced misunderstanding about singleton types compile-time type. Here is an example:
val x: Witness.`120`.T = 120.narrow
It works fine, b...
Pizor asked 16/12, 2019 at 10:42
1
My issue
I have the following type family that splits arguments off of a function:
type family
SeparateArgs
( a :: Type )
:: ( Type, [Type] )
where
SeparateArgs (a -> b) =
SndCons2 a (Se...
Remand asked 20/11, 2019 at 23:24
3
I have a class instance that has some relatively unintuitive constraints. This results in unreadable error messages if this constraint is violated. What I would like to do is provide a custom type ...
Prostyle asked 31/7, 2019 at 10:52
1
Considering https://speakerdeck.com/folone/theres-a-prolog-in-your-scala, I would like to "abuse" the Scala type system to find all instances of e.g. CanBuildFrom that match a given criteria. Prolo...
Citizenry asked 3/11, 2014 at 21:16
3
Consider following definition of a HList:
infixr 5 :>
data HList (types :: [*]) where
HNil :: HList '[]
(:>) :: a -> HList l -> HList (a:l)
And a type family Map to map over typele...
Depressor asked 17/9, 2019 at 11:16
1
Solved
I have a typeclass Search, which has an instance Search[A] if we have a TypeClass1[A] or a TypeClass2[A] instance. With preference given to the 1 instance.
The following compiles:
trait TypeClass...
Egoist asked 14/9, 2019 at 8:40
2
Solved
To motivate this question, let's first recall a bog-standard Hoare-Dijkstra-style indexed monad, and the example instance of an indexed writer monad.
For an indexed monad, we just require type ali...
Debi asked 15/7, 2019 at 13:1
2
Solved
I've got a type family defined as follows:
type family Vec a (n :: Nat) where
Vec a Z = a
Vec a (S n) = (a, Vec a n)
I'd like to assert that the result of applying this type family always fulf...
Appendicle asked 4/7, 2019 at 0:31
3
Solved
I have a type class that looks a bit like the following:
class Foo a b | a -> b where
f :: a -> Bool
g :: b -> Bool
h :: a -> b -> Bool
Or at least these are the bits that are ...
Revulsive asked 1/6, 2019 at 21:24
1
Solved
I recently read the very interesting paper Monotonicity Types in which a new HM-language is described that keeps track of monotonicity across operations, so that the programmer does not have to do ...
Burble asked 6/5, 2019 at 8:58
1
Solved
I'm trying to define some structure like this
case class Transformer[From, To](
name: String,
get: PaymentEvent => From,
to: From => To
I want to filter elements with names that are par...
Bassoon asked 16/4, 2019 at 12:26
1
Solved
Consider this code:
trait TypeOr[E, F] {
type T
}
implicit def noneq2[E, F](implicit ev: E =!= F): TypeOr[E, F] = new TypeOr[E, F] {
type T = (E, F)
}
sealed trait Error[+E, +A]
case cl...
Stardom asked 10/4, 2019 at 9:38
1 Next >
© 2022 - 2025 — McMap. All rights reserved.