Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [haskell]

Haskell is a functional programming language featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.

1
vote
1answer
21 views

How to run GHCi in command line like a regular shell command

Is there any way I can run GHCi on command line like a regular command in shell? For example: :browse in GHCi - list all the function for specific module. but I want to run it on shell, e.g.: ghci -...
0
votes
1answer
41 views

Haskell Conflicting family instance declarations

I try to define a division function for two Int types class Dnum a b where type DivType a b _div::a->b-> DivType a b instance Dnum Int Integer where type DivType Int Integer = ...
0
votes
1answer
26 views

Cannot install z3 package for Haskell on OS X

I'm trying to install the z3 package as follows: stack install z3 --extra-lib-dirs=/usr/local/bin --extra-include-dirs=/usr/local/bin Which brings up the following errors: Configuring z3-4.3.1... ...
0
votes
1answer
40 views

Custom monoid with WriterT

I am trying to implement WriterT with custom data type. I have implemented the monoid as the required by runWriterT. But I am unable to compile the code. I get an error Could not deduce (Semigroup (...
4
votes
0answers
46 views

Haskell DLL causes memory leak

I am working on a C++ project that uses a Haskell DLL (GHC version is 8.0.1 x64). I've noticed, that the executing program consumes much memory. I investigated into the matter and that's what I've ...
0
votes
1answer
39 views

How to get value out of nested synonym type

I have defined my own type called CtrlV: {-# LANGUAGE TemplateHaskell #-} import Data.Data (Data, Typeable) import Happstack.Server (Response, ServerPartT) import Web.Routes (RouteT) import Web....
0
votes
1answer
72 views

Discovering more typeclass instances

When I was new to Haskell I had very hard time finding instances for various types. Motivated by this, much later I noticed reifyInstances. While I know little about Template Haskell, it seems that ...
8
votes
6answers
227 views

Making a basic Haskell type an instance of a new typeclass

Say I'm trying to define a new typeclass in Haskell, and among other things, it must have a + operation: class Foo a where (+) :: a -> a -> a (In practice the typeclass Foo would have more ...
0
votes
1answer
64 views

How to create a newtype of parser?

newtype Parser a = PsrOf{ -- | Function from input string to: -- -- * Nothing, if failure (syntax error); -- * Just (unconsumed input, answer), if success. dePsr :: String ->...
0
votes
1answer
63 views

How does p >>= f works in Parser instance?

class Monad m where return :: a -> m a (>>=) :: m a -> (a -> m b) -> m b instance Monad Parser where return a = Parser (\cs -> [(a,cs)]) p >>= f = Parser (\...
1
vote
1answer
44 views

How to lens onto field of a record which is a polymorphic function?

I just installed the lens library so I can easily set in a nested data structure. However, i ran into a problem. Here is a minimal example to demonstrate my problem The following code doesn't compile:...
2
votes
1answer
79 views

How to retry blocking IO Action when timeout?

How does one deal with a blocking IO action in Haskell? How can I put this IO action inside a scope and manage this scope from another method? If the timeout is reached, I would just reinvoke this ...
5
votes
1answer
142 views

Is Behavior a Comonad?

Conal Elliott talks about Streams and Comonads here: http://conal.net/blog/posts/sequences-streams-and-segments However, he doesn't mention Behavior directly. So.. is Behavior a Comonad, and if so - ...
1
vote
1answer
40 views

How do I parse this GHC type check error message?

I have been stumped by this GHC (version 8.4.3) type check error. This is an extract from a Haskell Servant code base I am working on. If somebody can explain the reason for this message, I would be ...
-2
votes
0answers
44 views

What does empty parenthesis mean in type declaration? [duplicate]

put :: s -> State s () put s = StateOf (\s0 -> (s, ())) Don't understand what the empty parenthesis mean in these two lines.
-1
votes
1answer
94 views

Is there an “of” syntax in Haskell?

newtype State s a = StateOf (s -> (s, a)) deState :: State s a -> (s -> (s, a)) deState (StateOf stf) = stf instance Functor (State s) where -- fmap :: (a -> b) -> State s a -> ...
0
votes
1answer
58 views

Share http Manager between requests

I'm using the library http-client and http-client-tls to make http requests. The documentation https://haskell-lang.org/library/http-client mentioned "It is highly advisable to share your Manager ...
-1
votes
2answers
79 views

Can we declare a newtype with a function?

newtype State s a = StateOf (s -> (s, a)) (s -> (s, a)) is a function, isn't it? newtype State s a = State { runState :: s -> (s, a) } such expression make sense since record syntax is ...
-1
votes
1answer
65 views

Use where outside the Haskell function

I'm wondering whether we can use where outside a function? e.g. fun::Int->Int fun n = n + 1 main = do fun x where x = 30 Obviously it does't work when I compile it, I want to declare x as ...
0
votes
2answers
65 views

Understanding a let-expression in Haskell

I'm new to Haskell and currently studying it for an exam. I have been learning it from learnyouahaskell. I don't understand the following let-expression in the group function. splitWhen :: (a -> ...
1
vote
3answers
58 views

Haskell type inference (ReaderT and tuple)

Exploring this material: Lens over tea I've encountered an interesting (simple at first) point: ex3 :: (a, b) -> (b, a) ex3 = do a <- fst b <- snd return (b, a) Everything's fine, but ...
1
vote
1answer
55 views

succ not getting removed on pred

/* Define a Prolog predicate replicate/3 which corresponds to * the Haskell function of the same name, except that the numeric * argument is expressed symbolically. * * For example, replicate(s(s(...
0
votes
1answer
49 views

How to compose curried functions in Scala

Is it possible compose functions in Scala that are curried? For example: def a(s1: String)(s2: String): Int = s1.length + s2.length def b(n: Int): Boolean = n % 2 == 0 def x : String => String =&...
5
votes
1answer
113 views

Why do initial algebras correspond to data and final coalgebras to codata?

If I understand correctly, we can model inductive data types as initial F-algebras and co-inductive data types as final F-coalgebras (for an appropriate endofunctor F) [1]. I understand that according ...
0
votes
0answers
35 views

VSCode Haskelly error

I'm trying to use VSCode with the extension Haskelly to work with haskell. When I select a word, right click and choose "Go to definition" or "Peek definition" it displays No definition found for .... ...
-1
votes
0answers
19 views

Haskell HXT splitting up XML data

I'm pretty new to arrows so go easy on me... I'm trying to count the number of a specific nodes in an XML file. The XML file is layed out so that under the root, we have a list of scenes and under ...
3
votes
2answers
69 views

Haskell currying explanation needed

I'm trying to understand the concept of currying and went to the Haskell documentation. However, it says that f is the curried form of g Yet f takes two arguments and g only one. Since currying ...
0
votes
1answer
49 views

Haskell cannot match expected type 'Bool' to type [t0]

New to haskell and I keep running into this cryptic error when I try to pattern match a non empty list Code: type Bits = [Bool] nor :: Bits -> Bits -> Bits nor [] [_:__] = error "mismatched ...
4
votes
3answers
99 views

How does <*> derived from pure and (>>=)?

class Applicative f => Monad f where return :: a -> f a (>>=) :: f a -> (a -> f b) -> f b (<*>) can be derived from pure and (>>=): fs <*> as = ...
2
votes
1answer
29 views

How to implement correctly Foreign.Storable to create Vectors?

I have been working in a project that has been using lists to calculate artificial neural network operations. Now, I would like to transform that to Data.Vector to improve its efficiency. However, I ...
0
votes
0answers
49 views

Escaping character for full text search in sqlite and Haskell

I have the following program: {-# LANGUAGE OverloadedStrings #-} module Main where import Lib import Control.Applicative import Database.SQLite.Simple import Database.SQLite.Simple.FromRow data ...
2
votes
1answer
84 views

Why passing a concrete type to function solves the error?

p.s: I wasn't sure how to name my question, fell free to let me know how I should have named it. If not specifying the concrete type, I get this error, which is very clear and easy to solve: ...
0
votes
0answers
37 views

Yesod Type Error - AuthId master vs. Key User [duplicate]

I have a Yesod application. My current goal is to have the application use a email / password for authentication. However, I am running into a type error. I believe I am following the directions in ...
3
votes
2answers
139 views

Simulate a path-dependent type in Haskell

Here is a simplified example of what I want to do. Let's say you have a HList of pairs: let hlist = HCons (1, "1") (HCons ("0", 2) (HCons ("0", 1.5) HNil)) Now I want to write a function replaceAll ...
3
votes
1answer
86 views

Should Floating-Point RNG be preciser near 0?

The Floating-Point RNG from System.Random looks simple, yet inaccurate to me: instance Random Double where randomR = randomRFloating random rng = case random rng of (x,rng') -> ...
1
vote
1answer
32 views

text encoding when combining http-conduit and scalpel-core

{-# LANGUAGE OverloadedStrings #-} module Main where import Lib import Network.HTTP.Simple import qualified Data.ByteString.Lazy.Char8 as L8 import Text.HTML.Scalpel.Core import Data.Text.Lazy....
0
votes
1answer
54 views

How can I reconstruct a JSON array from a slice using lens?

I would like to extract a slice of a JSON array using lenses, and get a Value back. More specifically, I am trying to do the following: $ import qualified Data.ByteString.Lazy as LBS $ import Data....
1
vote
1answer
38 views

Error while getting current user id

I am running through a minor problem that I cannot solve. Yesod with postgres template. My goal is to create a new directory named after current uid. -- model -- User ident Text -- ... -- ...
-2
votes
2answers
78 views

Haskell Understand Definition of functions

I am not quite able to find a good manual for the following: If I want to get the definition of a functionality in Haskell, then I am using :t So for example with: :t sqrt :t (+) :t truncate I will ...
3
votes
1answer
66 views

How to define a Diagrams backend that combines several primitive backends

I would like to make the same program use two different Diagrams backends, notably diagrams-rasterific to generate PNGs, and diagrams-svg to generate SVGs, from the same diagram. Since Diagrams seems ...
1
vote
0answers
62 views

How to draw an ellipse in codeworld haskell given co-ordinates

I need to draw an ellipse given two co-ordinates Ellipse Coords Coords but i'm not sure how to do this with vertices, co-vertices, foci, and a centre point. I'm basically confused as to ...
0
votes
2answers
47 views

How to match constructor with codeworld function haskell

so I've looked around for hours and can't find an answer to match what I need, although many are along the same line so I'm sorry if this is somehow a repost. In haskell, I have this shapeToPicture :...
-1
votes
1answer
52 views

Haskell: Parse CSV file into list of lists of floats

I'm new to Haskell and trying to read a csv file and make a list of lists of floats and I get 'IO' compiler error. Ubuntu 18.04 with GHCI 8.0.2. CSV file looks like this: 2,112,66,22,0,25.0,0.307,...
1
vote
0answers
46 views

Row count and similar in Esqueleto

Ok, I'll be more concrete {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE ...
5
votes
1answer
84 views

How do I apply inductive reasoning to `GHC.TypeLits.Nat`?

Consider this definition of zip for the usual vectors length indexed by Peano numerals: {-# language DataKinds #-} {-# language KindSignatures #-} {-# language GADTs #-} {-# ...
8
votes
1answer
151 views

Proving a type inequality to GHC

For educational purposes, I have been trying to reconstruct an example from the book "Type-Driven Development with Idris" (namely RemoveElem.idr) in Haskell via use of various language extensions and ...
2
votes
1answer
45 views

Can't get rid of this type error

I'm trying to solve this problem. This is my code: import Data.List (nub) main = interact $ unwords . map show . solve . map words . lines solve :: [[String]] -> [Int] solve (_:r:_:a) = map (...
1
vote
3answers
65 views

What does <*> do in addRecip x y = fmap (+) (recipMay x) <*> recipMay y?

addRecip :: Double -> Double -> Maybe Double addRecip x y = fmap (+) (recipMay x) <*> recipMay y where recipMay a | a == 0 = Nothing | otherwise = Just (1 / a) I look ...
8
votes
3answers
336 views

Is there a shorthand for operations like `fromNewtype . f . toNewtype`?

A pattern that presents itself the more often the more type safety is being introduced via newtype is to project a value (or several values) to a newtype wrapper, do some operations, and then retract ...
-1
votes
1answer
58 views

Plotting a Random walk in Haskell

Im trying to plot a random walk in haskell. Im useing getStdGen for the random nummbers. Im useing Chart.Easy for the plotting. Im a pleb at haskell and I cant understand the compiler error Im getting....