How to do existential quantification with GADT?

I have the following data type: {-# LANGUAGE ExistentialQuantification #-} data ExType = forall a. One a | forall a. Two a | forall a. Three a With that I am able to create heterogeneous lists: [One 3, Two "hello", One 'G'] I have been told tha...
more »

2017-04-18 23:04 (2) Answers

BinaryTree in Haskell

I have to create a binarytree for a monte carlo tree search, and each node to contain a score, the number how many times it has has been visited and his children. I am beginner could you help me please? All I have is: "data Tree s a = _ " where "s"...
more »

2017-04-18 23:04 (0) Answers

Arithmetic error when trying to add two numbers

I tried to implement a function that takes a limit and a string, parses the string and tests if the parsed number exceeds the limit. The function works well only for strings without 0s in it, like "123". However, it could not parse strings correctly ...
more »

2017-04-18 16:04 (1) Answers

How to recreate an element in Threepenny GUI?

If I use the delete function on some Elements, how can I then recreate them (as in make them appear again)? I have looked around the examples and documentation, but I couldn't find any function that would allow me to do this except maybe mkElement w...
more »

2017-04-18 14:04 (2) Answers

Module-level tests in Haskell

I am getting acquainted to Haskell, currently writing my third "homework" to some course I found on the web. The homework assignment needs to be presented* in a file, named Golf.hs, starting with module Golf where. All well and good, this seems to be...
more »

2017-04-18 12:04 (2) Answers

extracting first two digits of a number haskell

I'm getting a frustrating error when I try to extract the first two digits of a number. First, I work out the length of digit using log, then I divide the number by the 10^(length of digit - 2) to extract the first two digits. The len and divisor fun...
more »

2017-04-18 08:04 (3) Answers

Function to turn a GenTree to a Binary Tree

Given the following data structures, create a function which given a GenTree, turns it into a BinTree: Each in order NodeG matches a NodeB node in the Binary Tree; The left son of NodeB matches the first son of NodeG; The right son of NodeB is the ...
more »

2017-04-17 19:04 (1) Answers

Generating end-point descriptions in Servant

Servant provides a way to generate documentation from the API definition. However, I see no way of (informally) documenting the functionality of each end-point. For the example used in the link above, the generated documentation contains: ## Welcome...
more »

2017-04-17 13:04 (1) Answers

Creating a data type list Haskell

I've done a personal list in Haskell like this: (2,(1,1),3) -> List [Num 2, List [Num 1, Num 1], List [Num 3]]. This is how I made it: data SList a = Num a | List [SList a] deriving Show emptySList :: SList a emptySList = (List []) consElem :: a ...
more »

2017-04-17 12:04 (1) Answers

haskell Binary Tree exercises

In Graham Hutton's book Programming in Haskell, there was an error in solving Chapter 10 Exercise 3. When the number of leaves on the left and right side trees is not more than one, these trees are said to be balanced. Of course, it seems to be bala...
more »

2017-04-17 04:04 (1) Answers

Build simple haskell library using nix

I've been interested in Nix for a while, and I thought I would finally try to use it for starting a new haskell project. I began with the directory structure project.cabal src/Lib.hs Where the cabal file has the following contents: name: project...
more »

2017-04-17 03:04 (1) Answers

Equivalent code in Haskell for !=

Is there an equivalent statement, in Haskell, for code similar to the following: x != y For instance: [x+y | x <- list1, y <- list2, x != y] How would I say the last bit: (x != y) in Haskell? ...
more »

2017-04-16 22:04 (1) Answers

How to combine two lists in Haskell

I want to make a list of lists like this: [1,2,3] [4,5,6] -> [[1,2,3], 4, 5, 6] This what i have by now: combine :: [a] -> [a] -> [[a]] combine xs ys = [xs,ys] But this code gives me: [[1, 2, 3], [4, 5, 6]] and is not what I need. ...
more »

2017-04-16 11:04 (2) Answers

How to run a stack build in a Docker container?

I'd like to set up a containerized build of a Haskell stack project for work. I know that stack --docker build exists, but I'd like to do this just with docker, so my colleagues are not required to first install stack. I currently have a Dockerfile ...
more »

2017-04-16 09:04 (1) Answers

fmapping arrows over monads

I understand that an Arrow is a Profunctor, where one can transform its input and its output, but can one map an arrow over a Functor? I understand that as-asked the answer is "no", since the fmap function type signature is (a -> b) -> f a -&g...
more »

2017-04-15 23:04 (2) Answers

error using stream package/data type

I have been stuck with a particular situation. I am not sure what the error even is to be honest. data Stream a = Cons a (Stream a) streamToList :: Stream a -> [a] streamToList (Cons x (Stream xs)) = x: streamToList (Stream xs) Doing something ...
more »

2017-04-15 22:04 (1) Answers

Illegal instance declaration for ‘Show DecV’

I'm trying to write a Parser for an extension of the While Language, called Proc, that takes input such as x:=1 and returns Ass "x" (N 1). My code so far is below: {-# LANGUAGE StandaloneDeriving #-} module Attempt where import Text.Megaparsec impor...
more »

2017-04-15 22:04 (1) Answers

Apply a function to a value inside IO Maybe

I have a function of type a -> IO (Maybe b) and I want to apply it to IO (Maybe a) and get IO (Maybe b). I wrote a function to do that: ioMaybeApply :: (a -> IO (Maybe b)) -> IO (Maybe a) -> IO (Maybe b) ioMaybeApply f ioMaybeA = do ma...
more »

2017-04-15 21:04 (1) Answers

Haskell error: Variable not in scope

I'm a bit new to Haskell but I've been working this problem for a couple hours with no luck. I'm trying to implement something similar to a filter, except a predicate and list is passed to a function and it returns a tuple of two lists, one which is...
more »

2017-04-15 19:04 (2) Answers

iterate and map

I'm trying to use iterate and map together but I'm stuck. I have a list of possible positions and an initial position: legal = [(0,1),(0,-1),(1,0),(-1,0)] initpos = (1,1) And a function: addTupple::(Int,Int)->(Int,Int)->(Int,Int) addTupple...
more »

2017-04-15 18:04 (2) Answers

x <*> y <$> z in Haskell

I'm trying to understand some Haskell source code, and I encountered this structure some times: x <*> y <$> z e.g. (+) <*> (+1) <$> a Can somebody explain this structure to me? I get that it translates to fmap a (+ a + 1...
more »

2017-04-15 17:04 (2) Answers