parametric-polymorphism

F#: arithmetic operator and loss of polymorphism (value restriction?)

与世无争的帅哥 提交于 2019-12-11 20:42:23
问题 This code doesn't compile: let f = fun x y -> x <<< y // bit shift let g = fun x y -> x <<< y [<EntryPoint>] let main _ = printfn "%d" <| f 1 10 printfn "%d" <| f 1L 10 // error printfn "%d" <| g 1L 10 0 (7,21): error FS0001: This expression was expected to have type int but here has type int64 http://ideone.com/qktsOb I guess the unifier fixed the type parameters associated with f and g upon seeing their first occurrences. What governs this process? I think this is very similar to "value

scala: Referencing Trait with F-Bound Parameters

前提是你 提交于 2019-12-11 17:26:18
问题 I am designing a F-Bound data type, and have a working companion object. I would like to reference this companion object from the trait itself, but I can't get the types right. trait A[AA <: A[AA]] { self => val data: String } case class A1(data : String) extends A[A1] trait B[BB <: B[BB, AA], AA <: A[AA]] { self: BB => val content: AA def companion: BComp[BB, AA] // What is the correct type? def companion2: BComp2[BB, AA] // What is the correct type? } trait BComp[BB[X <: BB[X, AA], Y <: AA

Modeling System F's parametric polymorphism at Set₀

三世轮回 提交于 2019-12-11 12:13:29
问题 In System F, the kind of a polymorphic type is * (as that's the only kind in System F anyway...), so e.g. for the following closed type: [] ⊢ (forall α : *. α → α) : * I would like to represent System F in Agda, and because everything is in * , I thought I'd interpret types (like the above) as Agda Set s; so something like evalTy : RepresentationOfAWellKindedClosedType → Set However, Agda doesn't have polymorphic types, so the above type, in Agda, would need to be a (large!) Π type: idType =

Appropriate use of universe polymorphism

假如想象 提交于 2019-12-11 06:29:42
问题 I've been working for a couple of weeks on an Agda project, glibly ignoring level polymorphism as much as I can. Unfortunately (or perhaps fortunately) I seem to have reached the point where I need to start understanding it. Until now I've been using level variables only when they are needed as a second argument to Rel (or third argument to REL ). Otherwise I have omitted them, just using Set directly. Now I have some client code that explicitly quantifies over levels a and tries to pass some

ml function of type fn : 'a -> 'b

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 18:19:32
问题 The function: fn : 'a -> 'b Now, are there any functions which can be defined and have this type? 回答1: There are two possible implementations for that function signature in Standard ML. One employs exceptions, the other recursion: val raises : 'a -> 'b = fn a => raise Fail "some error"; (* Infinite looping; satisfies the type signature, *) (* but won't ever produce anything. *) val rec loops : 'a -> 'b = fn a => loops a; The first solution may be useful for defining a helper function, say bug

Haskell partial function application with $

徘徊边缘 提交于 2019-12-10 15:49:14
问题 I'm new to Haskell and looking at a simple example of using function application with $ . It seems straightforward - it takes a function and applies it to a value. So this makes sense: > (+3) $ 2 5 This also makes sense: > ($) (+3) 2 5 This makes sense because the first argument is the function, and the second argument is the value. Now considering using $ to create a partial function. Looking at types, this makes sense - it just needs a Num type value for b : > :t ($) (+3) ($) (+3) :: Num b

How to use a generic class without the type argument in Swift?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 03:24:21
问题 I want to encapsulate a generic object in another class without setting the generic type argument. I created a base Animal<T> class and defined other subclasses from it. Example: public class Animal<T: YummyObject> { // Code } public class Dog: Animal<Bark> { // Code } public class Cat: Animal<Meow> { // Code } and defined an Animal property, without the type argument, in the UITableView extension bellow: extension UITableView { private static var animal: Animal! func addAnimal(animal: Animal

Why does GHC infer a monomorphic type here, even with MonomorphismRestriction disabled?

╄→гoц情女王★ 提交于 2019-12-09 14:19:35
问题 This was prompted by Resolving the type of `f = f (<*>) pure`, which discusses a more complicated example, but this one works too. The following definition compiles without problem: w :: Integral a => a w = fromInteger w ...Of course it doesn't work runtime-wise, but that's beside the question. The point is that the definition of w itself uses a specialised version of w :: Integer . Clearly that is a suitable instantiation, and therefore typechecks. However, if we remove the signature, then

Polymorphism in OCaml - ad hoc,parametric, inclusion/subtyping

孤人 提交于 2019-12-09 13:19:20
问题 I am having a problem understanding the different types of polymorphism, specifically in regards to OCaml. I understand that polymorphism allows for multiple types in OCaml denoted as 'a, but I do not understand what the different types of polymorphism are. If someone could give me an explanation with relatively low-level language that would be awesome! ad hoc, parametric, inclusion/subtyping 回答1: Here's an approximation. Ad-hoc polymorphism usually refers to being able to declare the same

Monadic substitution under binders

怎甘沉沦 提交于 2019-12-07 16:32:47
问题 In the following Agda code, I have a term language based on de Bruijn indices. I can define substitution over terms in the usual de Bruijn indices way, using renaming to allow the substitution to proceed under a binder. module Temp where data Type : Set where unit : Type _⇾_ : Type → Type → Type -- A context is a snoc-list of types. data Cxt : Set where ε : Cxt _∷_ : Cxt → Type → Cxt -- Context membership. data _∈_ (τ : Type) : Cxt → Set where here : ∀ {Γ} → τ ∈ Γ ∷ τ there : ∀ {Γ τ′} → τ ∈ Γ