Questions tagged [haskell]
Haskell is a functional programming language featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.
46,411
questions
0
votes
1answer
19 views
Understanding foldTree function
Looking at this definition appearing in Data.Tree:
foldTree :: (a -> [b] -> b) -> Tree a -> b
foldTree f = go where
go (Node x ts) = f x (map go ts)
My specific question is: as go ...
0
votes
0answers
11 views
How to decrement in recursive functions in Haskell?
I know how to do this perfectly in Python, but I am not sure how it would translate into Haskell. Basically, I am looking for a way to decrement a value each time a function is recursively called. I ...
1
vote
0answers
20 views
Unkown error message when trying to install Haskell Platform on Windows
When trying to install the Haskell Platform via Chocolatey as outlined in the default instructions at haskell.org/platform, I get an error when trying to install the cabal and ghc packages.
cabal ...
-2
votes
1answer
24 views
Cut list before last element that is equal to parameter
I need a function:
splitOn :: (Eq p) => p -> [p] -> ([p], [p])
So that:
splitOn 'b' ['a', 'b', 'b', 'b', 'c', 'a'] = (['a', 'b', 'b'], ['c', 'a'])
splitOn 'b' ['a', 'b', 'c', 'a'] = (['a'], ...
1
vote
1answer
33 views
How to constrain a class instance
I'm trying to apply a type constraint to an instance of a class that has kind ->.
data Data1 = Data1 String
class Class1 m where
c1f :: m -> m
instance Class1 Data1 where
c1f (Data1 v) ...
0
votes
0answers
27 views
How should I make environment variables available to my web app?
OS: Ubuntu 20.04 LTS
I am attempting to deploy a web app using Keter, the app depends upon several environment variables which I seem to be struggling to make available.
For reference I've been using ...
0
votes
1answer
37 views
quickCheck returns error when comparing zipWith functions
I created my own myzipWith function and want to compare it with the original zipWith with the use of quickCheck.
myzipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
myzipWith a y [] = []
...
5
votes
2answers
72 views
What does ' mean/do at the end of function name in Haskell?
I started with Haskell a few days ago and I found some solution at my problem online, but I start to noted that some function has a symbol at the end of the function name.
I want ask what is the ...
0
votes
1answer
59 views
Can trees be generalized to allow any traversable sub-tree?
Data.Tree uses a list to represent the subtree rooted at a particular node. Is it possible to have two tree types, for example one which uses a list and another which uses a vector? I want to be able ...
1
vote
1answer
41 views
How can I convert [[Char]] -> Char in Haskell?
I'm trying to output a bunch of cities in a nice text format, each one starting on a new line. With each piece of data comma separated. But I'm getting the error, cannot match expected type Char to ...
1
vote
1answer
18 views
Reading a nested list in a CSV column with Cassava
An example is easier to explain so I would like to parse this data into a datatype with cassava
title;authors
Cambridge Economic History;Ian MorrisWalter,ScheidelRichard,P Saller
I tried to do the ...
14
votes
1answer
1k views
Why doesn't Haskell need Trampolining?
As Scala developer learning the IO Monad, and therefore technicalities of Trampolining in general that are necessary for recursion where tail call optimization is not possible, I wonder how Haskell ...
3
votes
1answer
64 views
Typeclasses vs. functions?
I am currently experimenting with typeclasses & as an exercise, the ability to log in a variety of contexts (i.e. print to the console in the context of IO). I started off by implementing my ...
-1
votes
0answers
50 views
Dynamic programming in Haskell (Jednakost)
I'm trying to solve Jednakost problem by spoj.com.
The problem:
While browsing a math book, Mirko found a strange equation of the form A=S.What makes the equation strange is that A and S are not the ...
4
votes
2answers
113 views
Arrow “proc” notation in F#
Is there an implementation of "proc" notation for arrows in F#? In Haskell, it looks like this:
mean2 :: Fractional a => Circuit a a
mean2 = proc value -> do
t <- total -< ...
2
votes
1answer
54 views
Why is this lexer not parsing this input?
I want to lex the following code example:
prop levelBasedAlerter uni { a b } \I ->
levelBasedAlerter a
| a > I ->
b: ...
-2
votes
1answer
55 views
What does “Variable not in scope” mean and how to solve it? [closed]
I'm trying to create a code that calculates the module of a vector. But I get an error:
Variable not in scope
{-- Coordinates -
--}
pointX x1 x0 = abs (x1 - x0)
pointY y1 y0 = abs (y1 - y0)
q1 ::...
1
vote
3answers
67 views
“Pattern-matching” types in Haskell
I want a function f that acts as an increment on Ints and as an identity on all the other types. I tried to enable the TypeApplications extension and do this the most straight-forward way possible:
f :...
0
votes
1answer
86 views
What does 'p' represent in a function's type?
Given the following function definition:
f xs = []
its type is
f :: p -> [a]
From this, how should you interpret what p means?
Does it just mean anything? As in, f takes in literally-any-value ...
15
votes
3answers
581 views
Is Haskell's `Const` Functor analogous to the constant functor from category theory?
I understand that many of the names in Haskell are inspired by category theory terminology, and I'm trying to understand exactly where the analogy begins and ends.
The Category Hask
I already know ...
-1
votes
3answers
85 views
Return sublists in increasing length order
I am trying to create a Haskell function that takes a list of sublists as its argument and returns these sublists in order of increasing length. I have this but I am now stuck
increasing :: [[a]] ->...
1
vote
1answer
74 views
Checking if two lists are equal in Haskell
I am trying to create function setEqual.. This is what I have so far:
setEqual :: Eq a => [a] -> [a] -> Bool
setEqual [] _ = True
setEqual _ [] = ...
-3
votes
0answers
45 views
how to add various auxiliary functions and make them work [closed]
I did two auxiliary functions to help me with my goal (put the items from two lists in ascending order), but I am not able to make them work together, could you help me?
func :: [a] -> [a] -> [a]...
2
votes
1answer
61 views
Best practices with monad transformers : to hide or not to hide 'liftIO'
I will preface this by saying that I am a novice Haskell programmer (tinkered with it sporadically over the years) but I have a fair few years on the counter when it comes to OOO and imperative ...
4
votes
1answer
58 views
2 similar Haskell functions using do notation return same result but one is called many more times
nextState :: IO Int -> IO Int -- 0 1 0 2 0 1 0
nextState stateIO = do
value <- stateIO
putStrLn $ "Current state: " ++ show value
fmap (+1) stateIO
nextState' :: IO Int -> IO ...
1
vote
3answers
84 views
Understanding Monad CountMe's bind through equational reasoning or otherwise
This question arises from the section "Bad monads and their denizens" of section 18.5 "Monad laws" of the book "Haskell Programming from first principles".
data CountMe a ...
0
votes
1answer
53 views
decimal integer to Base4 string Haskell
I'm trying to convert an integer from decimal integer to a string based on base 4, but my unfoldr doesn't work and I'm not sure why or how to replace it. I can't use imports either. Please help me fix ...
1
vote
1answer
37 views
convert base 4 string to Decimal in Haskell
I have the following function that takes a string in the base of 4 and supposed to return a decimal integer, but my calculations seem to be off, so for "22" I need to get 10 but it's coming ...
-6
votes
1answer
84 views
If length is 2 do Haskell [closed]
I'm new to Haskell and I'm not sure how to work around the If-Else, for example:
function str = if ((length str) = 2) then (....)
In java we would:
if (str.length =2){
str = "2"}
else { ...
3
votes
1answer
54 views
Equivalent to Functor or Foldable for higher-kinded types
Consider this code, using the Functor and Foldable typeclasses:
{-# LANGUAGE DeriveFunctor, DeriveFoldable #-}
data Foo a = Foo (Maybe a) [a] deriving(Show, Functor, Foldable)
fmap (+1) (Foo (Just 1)...
0
votes
1answer
43 views
Is there any way to generate values for testing this way in Haskell QuickCheck?
I have 2 data types that I use for the representation of natural numbers in the unary system
data Valoare_Unar = Unu deriving(Show);
data Numar_Unar = Invalid | Unar [Valoare_Unar] deriving(Show);
I ...
5
votes
1answer
60 views
Haskell From First Principles Ch5, Ex 7,8
I'm new to Haskell and reading Haskell from first principles.
right now I'm on chapter 5.
while solving its exercises, specifically 7,8 I could not understand why I'm not coming up with right answer
...
-2
votes
2answers
58 views
How can I randomly generate a string 5 symbols long in haskell?
I'm a newbie so I'm having problems doing this:P
Currently I have tried this:
xs1 :: RandomGen g => Int -> g -> [[Char]]
xs1 n = sequence $ replicate n $ randomRs ('!', '~' ::Char)
but I can'...
0
votes
0answers
28 views
cabal-install failed to install a version that depends on the same version
I'm completely new to Haskell and I'm trying to replicate the code.world environment locally, so I need to install codeworld-api so that I can import CodeWorld. The problem is that when I run cabal ...
3
votes
2answers
43 views
How to define a simple RIO LogFunc without bracketing execution
I'm trying to set up logging in a RIO application; yet, I don't seem to understand the logging interface.
RIO documentation encourages to define a logger and run the application as follows:
...
0
votes
1answer
84 views
Typed version of Plutus Pionneers homework01 (week02) [closed]
I've tried to code a typed version of the first homework exercise. It compiles but fails to render in the playground...
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# ...
0
votes
1answer
82 views
Recursive syntax in haskell using and
I am trying to create a recursive function that takes and input List of List that looks like this: [[1,2], [4], [3], [1]] and returns a Bool. It is supposed to check whether all lists include at least ...
5
votes
1answer
140 views
Why does this function cause compile-time overflow?
struct Z;
struct S<N>(N);
struct MinHelper<N1, N2>(N1, N2);
trait Min {
type Val;
}
impl<N1> Min for MinHelper<N1, Z> {
type Val = Z;
}
impl<N2> Min for ...
1
vote
1answer
76 views
0
votes
1answer
46 views
How can I fix Haskell version conflicts with dependencies?
I have tried the command "cabal install HaskellAnalysisProgram" to install the Haskell package "HaskellAnalysisProgram" on my Macbook Pro of operating system macOS Big Sur version ...
1
vote
1answer
88 views
How to create a lattice-type data structure in Haskell?
I am trying to build a lattice-type of FCA-type of data structure in Haskell where I could check if two entities have a join or not. Actually, I'm not even sure that the lattice is the right structure ...
3
votes
1answer
75 views
What is a “System FC2 grammar for Kinds”?
I'm trying to wrap my head around this blog post about the ConstraintKinds extension.
There was a post in the comment section which I totally did not understand. Here it is:
Adam M says: 14 September ...
0
votes
1answer
64 views
Is there a way to hide gcd?
I am rewriting the gcd function for an assignment, but when I'm trying to hide gcd, like so:
import Prelude hiding ((gcd))
I get the error
Parse error on input'gcd'.
I'm certain I've completed the ...
3
votes
1answer
38 views
How do I access the `Constraint` kind properly?
I'm playing around with the ConstraintKinds in GHCi. In the linked post I found a nice example:
type NoConstraint = (() :: Constraint)
But I can't get it to work. GHCi outputs the Constraint kind ...
3
votes
2answers
70 views
Monadic Parser - handling string with one character
I was reading this Monadic Parsing article while I was trying to implement a pretty simple string parser in Haskell and also get a better understanding of using monads. Down below you can see my code, ...
0
votes
2answers
47 views
End program after number of inputs
What my program does? Take input from user, it needs to be between 0-99.
Program ends when user guesses the number "guess" which is 45 or after taking 10 tries.
The problem is that I cant ...
0
votes
1answer
56 views
Haskell RegEx Matching on UTF8 file
I wrote this function
module PdfParser (parseOptions) where
import Text.Regex.PCRE
import Data.List.Split
parseOptions :: String -> [String]
parseOptions s = splitOn "\n" (s =~ regex :: ...
4
votes
1answer
76 views
Type design for the AST of my language remembering token locations
I wrote a parser and evaluator for a simple programming language. Here is a simplified version of the types for the AST:
data Value = IntV Int | FloatV Float | BoolV Bool
data Expr = IfE Value [Expr] |...
0
votes
0answers
40 views
CSS not loading after switching from keter to reverse proxy with nginx
Problem: CSS was being applied to the site but after switching to reverse proxy and adding a security cert while changing nothing else, the CSS no longer loads.
Details: Initially the website was ...
0
votes
1answer
47 views
Haskell scripts with simple asserts
Many books and tutorials explain language features with small scripts that do asserts. If all the assertions pass, the process has an exit code of 0, and if any one fails, the process has a non-zero ...