Questions tagged [haskell]
Haskell is a purely functional programming language featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.
49,014
questions
0
votes
0
answers
4
views
Type not inferred by GADT match and functional depenency
I have a misunderstanding of the Haskell type system that I think may be common, but I cannot find an explanation for the specific type-checking failure shown by this simple example:
{-#LANGUAGE GADTs,...
0
votes
0
answers
16
views
Functor application over division
My question can be written in the context of lists. I have a function doing what is analogous to:
div' xs n = (*) (1 / n) <$> xs
Can this be simplified at all? I have been unable to work ...
1
vote
1
answer
29
views
Generating Simple List from 1 to 10 with haskell
I am new in Haskell, could guys help me how to generating list from 1 to 10
i try to make like this
seqList :: Integer -> [Integer]
seqList 1 = [1]
seqList n = n : seqList(n-1)
the result 10 to 1, ...
0
votes
1
answer
44
views
extracting the first element of a tuple via list comprehension in haskell
I tried to extract the first element of a tuple in a list of tuples in haskell via list comprehension but somehow it just outputs the first one and then stops, so I decided to do it via recursion ...
-1
votes
0
answers
86
views
How to get [Int] instead of [[Int]] Haskell
I am a newbie to Haskell functional programming. I've studied lambda functions, lists,types, record syntax, and functors from several sources like Learn You a Haskell for Great Good a book called Get ...
-1
votes
0
answers
51
views
Haskell comparing characters in a word
I'm trying to make a function that will check how many characters are matching in a word
The characters are non-repeating A-Z. The position of the letters doesn't matter
INPUT target = "ABCDE&...
0
votes
1
answer
67
views
How to get a record field? Haskell
I have a record of Person
data Person = Person
{name :: Name
,lastname :: LastName
,personId :: Int
,parentList :: [Int]
,childList :: [Int]
,siblingList ::[Int]
}
deriving (Show,Typeable,Data,...
0
votes
0
answers
39
views
How to plot/benchmark argument size vs runtime in Haskell?
I have an assignment of implementing RSA for my cryptography course. One of the requirements is to plot the encryption time vs size of n, where n is the product of two large primes p and q in bits. ...
4
votes
1
answer
72
views
How to get rid of these apparently superfluous `undefined`s?
I'm using GHC 9.2.2 and playing with OverloadedRecordDot and generic-lens. As an experiment, I want to use the overloaded dot as a "frontend" to the generic-lens functionality (including ...
-2
votes
0
answers
36
views
Cabal: Missing (or bad) C libraries: ssl, crypto
When I do cabal v2-build on macOS Monterey 12.3.1, I get the following error:
Failed to build hlibgit2-0.18.0.14. The failure occurred during the configure
step.
Build log ( /Users/user/.cabal/logs/...
1
vote
1
answer
70
views
How to use recursive in Haskell
I'm trying to understand how recursion works in haskell, I'm trying to do a function that multiply using a sum
Something like 4 * 5 = 4 + 4 + 4 + 4 + 4
My current function is
multiplicacao a b
| ...
0
votes
1
answer
90
views
Compare list of lists in Haskell
Supposing my list defined as [[Id, time, priority] , [Id, time, priority], [Id, time, priority] ... ]
In This exemple, i want to order my lists in an increasing way depending on the priorities and if ...
0
votes
2
answers
78
views
Polymorphic Types: representing multiple types using the same type synonym
My objective is giving two data types the same synonym.
I've minimized my question to the following question:
{-# LANGUAGE KindSignatures, Rank2Types #-}
class Things (h :: * -> *) where
newtype ...
-1
votes
0
answers
34
views
Benchmark one specific `Test.Tasty.Bench` benchmark in a module using `cabal bench`
I have a bunch of benchmarks and I want to run a specific benchmark among them.
I had asked a previous similar question for tests. But the same technique does not work for benchmarks. Here are ...
1
vote
3
answers
69
views
class instance selection of a function return value
I want to print the return type of a function ("Integer" in this case):
{-# LANGUAGE FlexibleInstances #-}
import Data.Default
class HasReturnType a where
getReturnType :: a -> String
...
2
votes
1
answer
48
views
map example in Effective Haskell (B2.0), Page 58
Just so you know, I am somewhat familiar with Haskell but not totally comfortable with it yet so I was going through the book 'Effective Haskell' which is still in early release at PragPub. I ran ...
-3
votes
1
answer
117
views
How can we build a modular system in Haskell? [closed]
Below is a concept that I have applied in OOP, and I would like to apply in FP (specifically Haskell). Everything that I have read says it is possible, but I can find no good examples. I understand ...
0
votes
0
answers
74
views
How to import Control.Lens in Haskell?
I am new to Haskell. I want to use Control.Lens package. I've read this and applied what it says but I get an error that says:
Resolving dependencies...
cabal-3.6.2.0.exe: Cannot build the ...
1
vote
2
answers
64
views
Haskell create functor with type constraints
I have this Haskell code fragment:
{-# LANGUAGE InstanceSigs #-}
module LatticePoint
where
import Data.List
data (Eq v) => LatticePoint v = LatticePoint{prob::Double, value::v}
instance ...
0
votes
0
answers
49
views
Capture input and direct output from and to desktop using Haskell?
I have a program which effectively shuffles the keys on the keyboard, remapping them randomly so each one corresponds to a different output than it normally produces.
My issue is that I am only ...
-6
votes
0
answers
50
views
Recursively convert Strings to Integers in Haskell [closed]
stringToInt :: String -> Int
Using this declaration, how can you recursively convert a string to Integer, using only prelude functions.
-2
votes
1
answer
67
views
Calculate the exponential of Natural Numbers in Haskell [closed]
data Nat = Zero | Succ Nat
In Haskell, using the declaration, how do you calculate the exponentiation of natural numbers n and m, n^m?
exponential :: Nat -> Nat
0
votes
1
answer
43
views
Problem with a list validation in Haskell
I'm creating a program that validate the time.
I have the following code:
data TimeError
= WrongHour Int
| WrongMinute Int
deriving (Eq, Show)
lookHour :: Int -> Validation [TimeError] Int
...
-4
votes
0
answers
78
views
Making a function with all 1's diagonally? [closed]
I'm fairly new to Haskell and need help making a function that creates a square matrix (list of lists) of size a with all 1's diagonally (other elements must be 0). Does anybody have an idea how to ...
2
votes
2
answers
107
views
How to preserve random numbers in Haskell iteration?
I'm trying to calculate growing list with random number.
The basic code is here:
import System.Random
randint :: IO Int
randint = randomRIO (0,1)
type Generation = [Int]
gnext :: Generation -> ...
3
votes
1
answer
61
views
What is the cause of the warning : Pattern match is redundant?
I am trying to solve an exercises that Convert Fahrenheit to Celsius and vice versa but I'm getting this warning:
Pattern match is redundant
In an equation for ‘tempToC’: tempToC temp = ...compile(-...
0
votes
1
answer
104
views
How to turn this recursive function into a list comprehension?
I've made a function that interchanges the elements of two lists in turn and it works recursively.
change :: [a] -> [a] -> [a]
change [] ys = ys
change xs [] = xs
change (x:xs) (y:ys) = x : y : ...
2
votes
0
answers
38
views
Is there a flipped `(.)`? [duplicate]
The standard library provides many flipped versions of standard operators. >>= has =<<, $ has &, etc.. Does . have a flipped version? I would really rather not have to define one ...
3
votes
2
answers
77
views
Haskell, Create a function given a specific type
I read many similar topics and still don't understand.
So the question is to create a function that has a specific type
for example given type Integer-> Integer a function that has that type is \x-&...
1
vote
1
answer
69
views
Haskell MVar & Text laziness comparison
I benchmarked the following code example with different variations of normal/lazy text and normal/strict MVar:
import Control.Concurrent.MVar
import qualified Data.Text ...
1
vote
0
answers
56
views
Problem with TypeNats vs bespoke data statement
I've been experimenting with an evalation function for a simple expression language, mainly as a way to familiarise myself with some Haskell extensions that I've not used before. The latest experiment ...
1
vote
1
answer
59
views
Haskell. Parsing command line arguments
I am learning Haskell programming language. Now I am studying IO. I'd like to write simple command line util. The util take two files (JSON or YAML), compare them and output the result of compare (...
0
votes
3
answers
108
views
How do you design similar types to enforce particular rules?
Suppose you have a naive vector type, such as
data Vector a
= V2 a a
| V3 a a a
I am interested in how you can — and how you should — implement particular logic specific to the type's constructor....
3
votes
0
answers
46
views
"* Missing (or bad) C library: OpenAL32" - from stack build for a haskell project
I have a stack project using Sound.ALUT. The project was building fine on both Windows and Mac before I added sound. (Sound.ALUT is a library layered over OpenAL.) Got thinks working on MacOS but ...
-1
votes
1
answer
62
views
Lazify State Machine
I am beginner to Haskell and I am trying to write a Lexer State Machine that is Lazy.
I have this code that definitive is no lazy code. Thus what kind of library or pattern should I use to lazy-fy ...
0
votes
1
answer
56
views
What do I need rseq for, if I can do all the job using rpar?'
I have the operation x*x + 2*y and I want to evaluate the left and right operands of the + concurrently.
My question is what is the difference between the following two implementations:
import Control....
1
vote
1
answer
51
views
Creating a function that makes an inversed matrix
I'm new to haskell and would like some ideas on how to create a function that would take every head element of multilist's lists and add it to a new multilist, then move on to second column and etc.. ...
0
votes
0
answers
63
views
In haskell, I am trying to implement a functin to get highest common divisor between two numbers, but I am getting an error
gcd a 0= 0
gcd 0 a =0
gcd a b = if a > b then (if mod a b == 0 then a else gcd a (b-1) ) else (if mod b a == 0 then b
else gcd (a-1) b )
This how I think it will be implemented
1- find greatest ...
0
votes
1
answer
48
views
Haskell: Trying to make tapyclasses ala Rust dyn Trait for a FSM
I am a Haskell beginner, And I am trying to make a Finite State machine in Haskell like the one that Rob Pike show in his conference about Lexing and Go. Trough Rust-like dyn Traits.
Like this one.
...
1
vote
0
answers
37
views
Repairing streamed HTTP chunks in Haskell conduit
I'm streaming chess PGNs from the Lichess API. Streaming is recommended, since any given user could have up to ~500,000 games stored. The goal is to parse the PGNs in a parsePGNStream conduit as they'...
2
votes
1
answer
50
views
How does a function with 'do' work in this context?
So I have found a function on this forum from about 7 years ago and wanted to figure out exactly the way it works as I'm quite new to Haskell and am struggling to understand it.
truths :: Int -> [[...
5
votes
1
answer
78
views
Haskell Strict MVar with Bang pattern
The following code example takes approx 2 seconds to execute. When the bang pattern in line 14 is removed however, it takes 60s. Can anyone explain what is going on?
I am using strict MVar so whatever ...
-3
votes
0
answers
46
views
What causes parse error in function name in Haskell? [closed]
I wrote this very simple function but when I try to compile the code it gives back a parse error at the function name. I have tried multiple re-writings of the function and similar code I found on the ...
0
votes
1
answer
45
views
Haskell: Non type-variable argument
everyone! I've been learning Haskell through this lecture series and I'm trying to work through the exercises for lecture 1 (linked in the description of the video). I'm having trouble with the ...
1
vote
1
answer
50
views
Template Haskell resolve type aliases
I'm using template Haskell to generate data about a type. For many reasons I need the type to be used to be "normalized". So it shouldn't be a type alias/synonym. I really don't want to ...
2
votes
1
answer
90
views
Understanding foldr and foldl functions
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr f v [] = v
foldr f v (x:xs) = f x (foldr f v xs)
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl f v [] = v
foldl f v (x:xs) =...
3
votes
1
answer
83
views
Haskell: Type Error Trying when using generics
I am a Haskell beginner, and when I compile the Haskell source code, when trying to make a function to implement an lazy at least as long as
module Main where
import Data.Maybe
main = undefined
...
1
vote
1
answer
66
views
Pattern match on Data.Text constant?
I guess I am blind or something, so that I could not find the idiomatic way to pattern match on Data.Text constants.
Basically, what I want to do is the following:
getTempDriverName dir >>= \...
0
votes
0
answers
70
views
Filter separate csv files in Haskell by column?
I'm learning Haskell and have been having difficulties with creating functions that parse csv files and filter them. I want to write a function(or multiple functions) that take in 2 csv files and ...
6
votes
1
answer
115
views
Is there a name for mapping recursive data types based on terminals and their ancestries?
Let's say I have a type that looks like this:
data Term a = Terminal a
| Application (Term a) (Term a)
| Abstraction String (Term a)
Now, I want to map Term a to Term b. Ideally, I would be able to ...