FAQ Database Discussion Community


Haskell: Type (without boilerplate) for a heterogeneous list of String and/or [String]?

list,haskell,types,existential-type,heterogeneous
I would like to have a heterogeneous list of String and [String], as such: strs = ["h", ["x", "y"], "i", ["m", "n", "p"]] I know I can do this with a custom data type: data EitherOr t = StringS t | StringL [t] eitherOrstrs :: [EitherOr String] eitherOrstrs = [StringS...

Scala existentials placeholder translation for M[_,_] where M[X,Y <: N[X]]

scala,existential-type
Given the following types trait N[X] trait M[X, Y <: N[X]] How does scala translate this: M[_,_] I've tried the following but without success: scala> import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._ scala> typeOf[Class[_]] =:= typeOf[Class[C] forSome { type C }] res4: Boolean = true scala> typeOf[List[Class[_]]] =:= typeOf[List[Class[C] forSome { type C...

Haskell: Heterogeneous list for data with phantom variable

haskell,gadt,existential-type,phantom-types
I'm learning about existential quantification, phantom types, and GADTs at the moment. How do I go about creating a heterogeneous list of a data type with a phantom variable? For example: {-# LANGUAGE GADTs #-} {-# LANGUAGE ExistentialQuantification #-} data Toy a where TBool :: Bool -> Toy Bool TInt...

Difference between modules and existentials

module,ocaml,existential-type
It's folk knowledge that OCaml modules are "just" existential types. That there's some kind of parity between module X = struct type t val x : t end and data 'a spec = { x : 'a } data x = X : 'a spec and this isn't untrue exactly....

universal and existential quantifier in prolog

prolog,universal,existential-type,quantifiers
How can I implement following rules in prolog. I write the “ No spiders are mammals” sentence as Existential and universal: ¬∃x(mammals(X) ∧ spider(X) ) //It is not the case that mammals are spider ∀X(mammals(X) ⇒ ¬spider(X)) //All mammals are non-spider. ...

Translate/encode Haskell's `data Obj = forall a. (Show a) => Obj a` in Scala

scala,haskell,typeclass,implicit,existential-type
I've not been able to come up with how to encode Obj in Scala: {-# LANGUAGE ExistentialQuantification #-} data Obj = forall a. (Show a) => Obj a instance Show Obj where show (Obj a) = "Obj " ++ show a main = print $ show [Obj "hello", Obj 3,...