Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
1 answer
81 views

How does the arrow operator in haskell make sense in functions that take more than one parameter?

FYI: Second day into Haskell MRE (what the function does, does not matter): foo :: Int -> Int -> Int foo x y | x == y = x + y | x < y = x | x > y = y This is what ...
kesarling's user avatar
  • 2,102
1 vote
1 answer
83 views

Finding the type of functions

I have a problem regarding finding the type in Haskell. The question is as follows: Find the type of uncurry curry Does anyone know a way to find the type? The answer should be ((b1, b2) -> c, b1)...
Gustav Persson Skytting's user avatar
8 votes
1 answer
314 views

A type with `Eq a` but not `Ord a`

In (an idealized version of) Haskell, is there a concrete type a such that we can implement Eq a lawfully, but it is impossible to implement Ord a? The order doesn't need to be meaningful, and any ...
Trebor's user avatar
  • 430
2 votes
1 answer
83 views

Writing foldLeft equivalent for recursion schemes

This is a definition of foldr and foldl in terms of foldr: foldr :: (a -> b -> b) -> b -> [a] -> b foldr f z [] = z foldr f z (x:xs) = f x (foldr f z xs) foldl :: (a -> b -> ...
cocorudeboy's user avatar
2 votes
0 answers
66 views

Multiparameter classes versus data types [closed]

It often happens that we get to choose between writing a (often multiparameter) class or using some (sometimes n-ranked) data type. Let me give two examples to clarify my point: Example 1 An action of ...
141592653's user avatar
  • 689
2 votes
1 answer
50 views

Are fold and unfold required when recursive types appear in a language?

Are fold and unfold required when recursive types appear in a language? I'm reading "Types and Programming Languages" book by Benjamin C. Pierce. Section 4, “Recursive Types,” introduces ...
otstalyi's user avatar
  • 163
1 vote
0 answers
30 views

Haskell: Rigid type binding [duplicate]

The following code works as expected: data Test a = Test { sample :: [a], underflow :: a, width :: a, bounds :: Int -> a } test :: Num a => [a] -> a -> a -> ...
Chirmol Studio's user avatar
2 votes
2 answers
84 views

Extract a Maybe from a heterogeneous collection

I have a project where I define a "heterogenous list" like the following. I'm not sure what this trick is called but I've found it to be useful: {-# LANGUAGE KindSignatures #-} {-# LANGUAGE ...
tom's user avatar
  • 1,132
1 vote
2 answers
95 views

Confusion about list types in Haskell

As far as I understand [a] means that there can be a list that can have any number of nested lists inside. f :: [a] -> a f (x:xs) = x It is possible to call f [[1,2]] or f [[[True]]]] without ...
Filat Nicolae's user avatar
2 votes
2 answers
107 views

Iterate over a type level list and call a function based on each type in the list

Given a list of types {-# LANGUAGE DataKinds #-} type MyTypes = '[String, Int, Char] and a type class similar to the following: class MyClass a where describe :: Proxy a -> String instance ...
l7r7's user avatar
  • 1,256
-1 votes
1 answer
110 views

Non-associativity in a Haskell AST

I have been given the task of writing a parser for which I shall be able to write a composit function f(x)(y). In the specific parser I am to write, this is unlike functions in most languages a non-...
Piskator's user avatar
  • 647
4 votes
2 answers
71 views

Admissble type role overrides

In GHC Haskell, Map k v has a type role declaration for k to be nominal. This is because the user can otherwise coerce k to another type with the same representation but different Ord instance, ...
Trebor's user avatar
  • 430
4 votes
2 answers
205 views

rankN type equivalent for mypy in python

In Haskell we can use rankN types like so: rankN :: (forall n. Num n => n -> n) -> (Int, Double) rankN f = (f 1, f 1.0) Is the same thing possible in python with mypy? I tried the following ...
petrucci4prez's user avatar
1 vote
1 answer
67 views

How to convert between custom constant types in Haskell?

I am doing a problem on Exercism.org (specifically meetup). To reduce it to a minimal example, I am going to solve a slightly simpler problem that illustrates the same issue. Added for context after ...
Damien Martin's user avatar
1 vote
2 answers
104 views

Haskell binary datatype of specific bitwidth

I would like to create a datatype representing a binary number of specific bit width. So a type bin3 --> 0bXXX, bin7 --> 0bXXXXXXX Does anyone know how to do this? I have tried to install ...
confusedandsad's user avatar

15 30 50 per page
1
2 3 4 5
156