higher-rank-types Questions

3

Solved

During play around objective package, I noticed following type has interesting property. > {-# LANGUAGE RankNTypes #-} > data N f r = N { unN :: forall x. f x -> (x, r) } It is a Functo...
Compress asked 29/4, 2016 at 3:23

1

Solved

I have the following Rank 2 function: polyOn :: (f a -> f b -> c) -> (forall k . k -> f k) -> a -> b -> c polyOn bifunc func x y = bifunc (func x) (func y) I'd like to flip i...
Novanovaculite asked 1/11, 2021 at 11:22

4

Solved

Higher rank types look like great fun. From the Haskell wikibook comes this example: foo :: (forall a. a -> a) -> (Char,Bool) foo f = (f 'c', f True) Now we can evaluate foo id without the...

4

Solved

I have a trait that has a function for deserializing an associated type. However that associated type needs to have a lifetime that the caller decides, so I have a separate trait that I use a highe...
Sholley asked 28/2, 2020 at 21:40

4

Solved

I understand how forall enables us to write polymorphic function. According to this chapter, the normal function which we generally write are Rank 1 types. And this function is of Rank 2 type: fo...
Hazel asked 12/3, 2014 at 19:43

2

Solved

Lately I have been playing with this type, which I understand to be an encoding of the free distributive functor (for tangential background on that, see this answer): data Ev g a where Ev :: ((g ...
Azotemia asked 30/6, 2019 at 17:27

1

This question is actually a small lattice of very closely related questions; I don't think it makes much sense to break it up as yet. One of the fundamental ways to create a Vector is using unsafe...
Idel asked 12/4, 2018 at 21:6

1

Solved

I have a pluggable runtime type checker that supports parametric but no ad-hoc polymorphism, because there is no compiling step and type information are erased as soon as the type checker is deacti...

2

Solved

When I declare this newtype: newtype ListScott a = ListScott { unconsScott :: (a -> ListScott a -> r) -> r -> r } which would define the hypothetical rank-2 type ListScott :: ((...

5

Solved

I am not really proficient in Haskell, so this might be a very easy question. What language limitation do Rank2Types solve? Don't functions in Haskell already support polymorphic arguments?
Wedlock asked 20/8, 2012 at 3:8

3

Solved

Perhaps this is a stupid question. Here's a quote from the Hasochism paper: One approach to resolving this issue is to encode lemmas, given by parameterised equations, as Haskell functions. In ...
Photosphere asked 13/5, 2015 at 20:40

1

Solved

A type like Maybe (Lens' a b) doesn't work because Lens' is under the hood a Rank-2 type, that can't be wrapped in a type constructor without the -XImpredicativeTypes extension (which is not really...
Harmonicon asked 7/1, 2017 at 15:7

1

Solved

I'm trying to study church numerals in Haskell by giving the numbers a type like this, with the idea that a natural number n is basically the expression that applies the function in the following t...
Flaminius asked 29/10, 2016 at 2:53

1

Solved

All the experiments described below were done with GHC 8.0.1. This question is a follow-up to RankNTypes with type aliases confusion. The issue there boiled down to the types of functions like thi...
Stanger asked 26/10, 2016 at 22:39

1

I'm trying to understand how type constraints work with type aliases. First, let's assume I have next type alias: type NumList a = Num a => [a] And I have next function: addFirst :: a ...
Pantaloons asked 26/10, 2016 at 2:43

2

Solved

I was messing around with the runST function. Which has type (forall s. ST s a) -> a and it seems like trying to use it in any way that isn't directly applying without any indirection breaks it ...
Inoculation asked 30/8, 2016 at 6:40

1

Solved

In my (might incorrect) understanding, following two lists should be equivalent: [1, "a"] :: [forall a. Show a => a] data V = forall a. Show a => V a [V 1, V "a"] :: [V] However, the firs...

1

Solved

I ran in to a puzzling situation with a higher rank type. I figured out how to make it work, but I don't understand the difference between the working and non-working versions. With these backgrou...
Wan asked 26/3, 2015 at 18:3

3

Solved

What is the difference between f1 and f2? $ ghci -XRankNTypes -XPolyKinds Prelude> let f1 = undefined :: (forall a m. m a -> Int) -> Int Prelude> let f2 = undefined :: (forall (a :: k)...
Donniedonnish asked 27/2, 2015 at 19:21

2

Solved

Using RankNTypes, I define a type that doesn't depend on a type variable. Is this the right way to go around the case below? I need to define a few functions to be used inside ST s, which, of cour...
Distraction asked 14/1, 2015 at 12:20

1

Solved

I implemented transducers in Haskell as follows: {-# LANGUAGE RankNTypes #-} import Prelude hiding (foldr) import Data.Foldable type Reducer b a = a -> b -> b type Transducer a b = forall ...

1

Solved

I can only do rank-n types in Idris 0.9.12 in a rather clumsy way: tupleId : ((a : Type) -> a -> a) -> (a, b) -> (a, b) tupleId f (a, b) = (f _ a, f _ b) I need the underscores where...
Bugloss asked 5/4, 2014 at 11:30

1

Solved

This compiles fine: type List a = [a] But when I introduce a class constraint, the compiler asks for RankNTypes to be included: type List2 a = Num a => [a] After including that extension, ...
Branham asked 8/4, 2014 at 18:28

2

Solved

I am developing a relatively simple program (a calculator actually). However, I have decided to make all components of my program as generic as possible because: It's good practice. It keeps thin...

1

Solved

runST is a Haskell function that statically constrains the usable lifetime of a resource through types. To do this it uses rank-2 polymorphism. Standard ML's simpler type system only offers rank-1 ...
Cab asked 10/6, 2014 at 7:59

© 2022 - 2024 — McMap. All rights reserved.