Questions tagged [forall]

Haskell extension and keyword used to define rank-n and existentially quantified types or to use scoped type variables

forall is a keyword found in the programming language (with extensions), used in type specifications.

It can be used to define rank-n and existentially quantified types or to use scoped type variables. For more information, see What does the `forall` keyword in Haskell/GHC do?.

116 questions
377
votes
8 answers

What does the `forall` keyword in Haskell/GHC do?

I'm beginning to understand how the forall keyword is used in so-called "existential types" like this: data ShowBox = forall s. Show s => SB s This is only a subset, however, of how forall is used and I simply cannot wrap my mind around its use in…
JUST MY correct OPINION
  • 35,674
  • 17
  • 77
  • 99
50
votes
5 answers

forall in Scala

As shown below, in Haskell, it's possible to store in a list values with heterogeneous types with certain context bounds on them: data ShowBox = forall s. Show s => ShowBox s heteroList :: [ShowBox] heteroList = [ShowBox (), ShowBox 5, ShowBox…
missingfaktor
  • 90,905
  • 62
  • 285
  • 365
34
votes
4 answers

What does "exists" mean in Haskell type system?

I'm struggling to understand the exists keyword in relation to Haskell type system. As far as I know, there is no such keyword in Haskell by default, but: There are extensions which add them, in declarations like these data Accum a = exists s.…
Valentin Golev
  • 9,965
  • 10
  • 60
  • 84
17
votes
1 answer

What are these explicit "forall"s doing?

What is the purpose of the foralls in this code? class Monad m where (>>=) :: forall a b. m a -> (a -> m b) -> m b (>>) :: forall a b. m a -> m b -> m b -- Explicit for-alls so that we know what order to --…
Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
13
votes
1 answer

Explicit forall on a type class function

Since ghc-8.0 we have a very nice extension called TypeApplications. Which allows us instead of: λ> show (5 :: Int) "5" do so something like that: λ> :set -XTypeApplications λ> show @Int 5 "5" Which is really cool. It becomes a bit more involved…
lehins
  • 9,642
  • 2
  • 35
  • 49
12
votes
1 answer

Using Contract.ForAll in Code Contracts

Okay, I have yet another Code Contracts question. I have a contract on an interface method that looks like this (other methods omitted for clarity): [ContractClassFor(typeof(IUnboundTagGroup))] public abstract class ContractForIUnboundTagGroup :…
Dan Bryant
  • 27,329
  • 4
  • 56
  • 102
11
votes
1 answer

`forall {..}` in GHC 9

This is valid syntax in GHC 9. What do the {..} mean (as distinct from (..) which GHC 8.10 requires here)? ign :: forall {f :: Type -> Type} {p}. Applicative f => p -> f () ign _ = pure ()
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
11
votes
2 answers

Why does `forall (a :: j) (b:: k)` work differently than `forall (p :: (j,k))`?

I'm trying to understand the difference between using forall to quantify two type variables and using forall to quantify a single type variable of tuple kind. For example, given the following type families: {-# LANGUAGE RankNTypes #-} {-# LANGUAGE…
rampion
  • 87,131
  • 49
  • 199
  • 315
11
votes
4 answers

Understanding forall in Monad '>>=' function?

Following this answer, I've implemented a generic lift function in my program: liftTupe :: (x -> c x) -> (a, b) -> (c a, c b) --This will error liftTuple :: (forall x. x -> c x) -> (a, b) -> (c a, c b) I understand, that in this context, forall is…
Babra Cunningham
  • 2,949
  • 1
  • 23
  • 50
10
votes
2 answers

What does type signature for `undefined` mean in Haskell?

I am a beginner in Haskell and I am taken aback by the undefined function's type signature. I expected something more simple, but I found this on Hackage: undefined :: forall (r :: RuntimeRep). forall (a :: TYPE r). HasCallStack => a A special…
mkUltra
  • 2,828
  • 1
  • 22
  • 47
10
votes
2 answers

Code contracts, forall and custom enumerable

I am using C# 4.0 and Code Contracts and I have my own custom GameRoomCollection : IEnumerable. I want to ensure, that no instances of GameRoomCollection will ever contain a null value element. I don't seem to be able to this, though.…
Stephan
  • 101
  • 4
9
votes
2 answers

Multiple SQL statements in FORALL loop

I want to insert in Different tables with only single FORALL Loop in oracle.but FORALL don't support it.any idea how can i do it?? create or replace PROCEDURE test IS TYPE avl_web_details IS TABLE OF available_web_details%ROWTYPE; …
Asha Koshti
  • 2,763
  • 4
  • 22
  • 30
7
votes
1 answer

How to add an extra project into existing Android operating system source?

I am working on kernel development in AOSP, and the kernel repository that I work on is not a part of the operating system. It has an individual git repository. So when I try to push all AOSP sources into the server, I cannot see the kernel sources…
albin
  • 773
  • 1
  • 8
  • 27
6
votes
3 answers

How can I ensure that my Fortran FORALL construct is being parallelized?

I've been given a 2D matrix representing temperature points on the surface of a metal plate. The edges of the matrix (plate) are held constant at 20 degrees C and there is a constant heat source of 100 degrees C at one pre-defined point. All other…
EMiller
  • 2,792
  • 4
  • 34
  • 55
5
votes
1 answer

How to understand the universal quantification in Yoneda's natural isomorphism?

While learning about the Yoneda lemma, I came across the following encoding of the underlying natural isomorphism in Haskell: forward :: Functor f => (forall r . (a -> r) -> f r) -> f a forward f = f id backward :: Functor f => f a -> (forall r.…
michid
  • 10,536
  • 3
  • 32
  • 59
1
2 3 4 5 6 7 8