scala,haskell,typeclass,implicit,existential-type

You got it almost right: import scalaz._ import scalaz.Scalaz._ trait Obj { type T // existential type val x: T implicit val show: Show[T] } implicit val objSow: Show[Obj] = Show.shows[Obj] { (x: Obj) => x.show.shows(x.x) } object Obj { /* "constructor" */ def apply[U](_x: U)(implicit _show: Show[U]): Obj =...

If you rewrite your F definition as below it will work: {-# LANGUAGE RankNTypes #-} class C a where data F = F (forall a. C a => a -> Int) makeF :: F makeF = F $ const 1 I'm trying to understand why myself: Your original type says...

prolog,universal,existential-type,quantifiers

Suppose you have a database with the following facts: mammals(cat). mammals(dog). ... spider(blackwidow). ... Now you can issue a rewrite your sentence into a prolog query quite straightforward: ¬∃x(mammals(X) ∧ spider(X) ) //It is not the case that mammals are spider ?- \+((mammals(X), spider(X))). true. and ∀X(mammals(X) ⇒ ¬spider(X)) //All...

Scala translates M[_,_] into M[X, Y] forSome { type X; type Y }. This is easily proven: scala> type Foo = M[_,_] defined type alias Foo scala> type Bar = M[X, Y] forSome { type X; type Y } defined type alias Bar scala> implicitly[ Foo =:= Bar] res0: =:=[Foo,Bar]...

haskell,types,existential-type

This is a little tricky to ask without a bit more knowledge of what exactly you want to do, but I'll take a stab. Linear.V gives you n-dimensional vectors for any n. In linear, matrices are defined as vectors-of-vectors - Linear.Matrix defines the operations on such values. Linear.Matrix works over...

haskell,types,monads,existential-type,impredicativetypes

Do you need to have it untyped? If you're willing to use advanced GHC features, you can do something like this: {-# LANGUAGE GADTs, DataKinds, KindSignatures, TypeOperators #-} {-# LANGUAGE FlexibleInstances, FlexibleContexts #-} module Stack (Stack(..), push, pop, top, empty) where data Stack (h :: [*]) where Empty :: Stack...

haskell,types,typeclass,existential-type

First of all, to reference type variables in the type signature from the body of the function, you need to enable ScopedTypeVariables, and add a forall to the type: {-# LANGUAGE ScopedTypeVariables #-} display :: forall a c . (HasComponent (DisplayData a) c, HasComponent (Displayer a) c) => Entity c...

haskell,types,existential-type

One way how to implement type classes is passing a dictionary of functions that implement a type class under the hood. For example a function with signature f :: Show a => T would be translated into f' :: (a -> String) -> T by the compiler and whenever show...

haskell,existential-type,data-kinds

If you want to do runtime case analysis on the existential type, you need a singleton representation too: {-# LANGUAGE DataKinds, GADTs, KindSignatures, ScopedTypeVariables #-} data K = A | B -- runtime version of K. data SK (k :: K) where SA :: SK A SB :: SK B...

Completing gsg's answer on your third point. There are two kinds of way to use modules: As a structuring construct, when you declare toplevel modules. In that case you are not really manipulating existential variables. When encoding the module system in system-F, you would effectively represent the abstract types by...

list,haskell,types,existential-type,heterogeneous

This will work for arbitrarily nested lists of strings with a few extension tricks: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedLists #-} import GHC.Exts import Data.String data MyStringListThingy = String String | List [MyStringListThingy] deriving (Eq, Show) instance IsString MyStringListThingy where fromString = String instance IsList...

haskell,gadt,existential-type,phantom-types

Start with the Toy type: data Toy a where TBool :: Bool -> Toy Bool TInt :: Int -> Toy Int Now you can wrap it up in an existential without over-generalizing with the class system: data WrappedToy where Wrap :: Toy a -> WrappedToy Since the wrapper only holds...

The type of the expression p in p.toString is the skolemization of T forSome {type T}, per SLS section 6.1: The following skolemization rule is applied universally for every expression: If the type of an expression would be an existential type T , then the type of the expression is...

A couple of observations to start with: X forSome { type X } is just a fancy way of writing Any—it's a type we don't know anything about, so it must be at the top of the type hierarchy. If you don't believe me, ask the compiler: scala> implicitly[Any =:=...

scala,generics,types,existential-type

They are very similar indeed, and you are not alone in the confusion. The best article I've read about existential types gives you a good explanation is indeed here (as @DaunnC mentions) . There is actually also a third way to express the same in Abstract Types. As reasons go,...

scala,design-patterns,dependency-injection,existential-type

@wingedsubmariner is right that you can add type Api = ApiLike in the implementation. But that's too restrictive. I'll explain what else works and how you can figure it out. Since ApiComponent only declares that Api <: ApiLike — that is, Api >: Nothing <: ApiLike, Api could well be...

scala,hadoop,hbase,apache-spark,existential-type

That's very strange, are you 100% sure you have your imports correct (EDIT: yes, this was problem, see comments), and you have the correct versions of artefacts in your build file? Maybe it could help you if I provide a code snippet from my working project: import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.mapred.JobConf...