Menu
  • HOME
  • TAGS

Why does introducing associated types kill my performance?

haskell,type-families,associated-types

By sheer chance I just stumbled upon this question: Transitivity of Auto-Specialization in GHC There the OP quotes "From the docs for GHC 7.6:" (emphasis mine): [Y]ou often don't even need the SPECIALIZE pragma in the first place. When compiling a module M, GHC's optimiser (with -O) automatically considers each...

How do I disambiguate associated types?

rust,associated-types

You can use what is currently called Universal Function Call Syntax (UFCS): fn gimme_a() -> <Self as HasA>::A; fn gimme_a() -> <Self as RichHasA>::A; ...

Self as argument type of generic callback

swift,callback,associated-types

i think swift is buggy at this place. maybe you can use protocol Proto { typealias ItemType func register(tag: String, cb: (Self, Self.ItemType)->()) func unregister(tag: String, cb: (Self, Self.ItemType)->()) } class Foo : Proto { func register(tag: String, cb: (Foo, Int)->()) { } func unregister(tag: String, cb: (Foo, Int)->()) {...

Swift - Associated value or extension for an Enum

swift,enums,associated-object,associated-types,computed-values

Unfortunately you cannot define static properties based on enum cases, but you can use computed properties and switch to return values for each case: enum Icon { case plane case arrow case logo case flag var image: UIImage { switch self { case .plane: return UIImage(named: "plane.png")! case .arrow: return...

traits and associated-types

rust,traits,associated-types

Here there's the correction: pub trait Directory<P: Person> { type Per : Person = P; fn get_person(&self) -> Self::Per; } The type Per in Directory can be redefined in trait implementations. The compiler doesn't know if Self::Per (which is the re-defined Per in the implementation) implements the trait Person, so...

Traits with default methods that depend on a bound of an associated type

rust,associated-types

This code now compiles as desired: trait DigitCollection: Sized { type Iter: Iterator<Item = u8>; fn digit_iter(self) -> Self::Iter; fn digit_sum(self) -> u32 { self.digit_iter() .map(|digit: u8| digit as u32) .fold(0, |sum, digit| sum + digit) } } fn main() {} ...

Error when writing a recursive trait method with an associated type as an argument

generics,recursion,rust,traits,associated-types

First of all: given an object x implementing Node, x.inputs() takes a generic parameter N and returns Vec<&mut N>. Now let’s write out a more explicitly typed version of what’s happening in output_requested. (Incidentally, with the fancy new IntoIterator basis of the for loop, the .into_iter() is no longer necessary.)...