How does listx2 = [x * 2 | x<- numberList] work?

So I m watching a very basic Tutorial, and I m at list comprehension where this comes up: listx2 = [x * 2 | x<- numberList] with numberList being a list of numbers So this takes every number in the list and duplicates it, so numberList = [1,2...
more »

2017-07-18 22:07 (2) Answers

What are binary operators in haskell

So I wanted to understand the functions foldl and foldr in Hoogle they say that these functions apply to binary operators. But I don't get what these binary operators are. I know that (+) and (-) are binary operators but what defines them ? ...
more »

2017-07-18 21:07 (1) Answers

Type-level graphs via GADTs and DataKinds

I'm trying to encode a type-level graph with some constraints on the construction of edges (via a typeclass) but I'm running into an "Illegal constraint in type" error when I try to alias a constructed graph. What's causing this issue? If it's unwo...
more »

2017-07-18 19:07 (0) Answers

ghci / stack and package available

I use intero with some file with no project, and my global (or local stack.yaml) is: ~/.stack/global $ cat stack.yaml flags: {} packages: [] extra-deps: [] resolver: lts-8.21 If I stack exec -- ghci and :l Intero.hs where Intero.hs contains: $ ...
more »

2017-07-18 18:07 (1) Answers

Run processes concurrently with stdin, stdout

How can I expand "Running processes concurrently" to include stdin and stdout ? For example, let's say that my (Windows) command outputs 10 on stdout, and I want to check that the output of all processes are correct : let cmds = replicate 100 "echo...
more »

2017-07-18 18:07 (1) Answers

Conditional selection of integer simple in Stack

Due to licensing constraints, we need to use the integer-simple variant of GHC when compiling in Windows platforms. Currently this is specified in our stack.yaml file: ghc-variant: integersimple # ... extra-deps: - text- # Override default fl...
more »

2017-07-18 12:07 (1) Answers

Hide State in Haskell - Lazyset

I'm trying to build a datastructure in Haskell that allows efficient lookup in an ordered, infinite list. If this was Java, I'd do something like this: class LazySet<T> { private Iterator<T> source; private NavigableSet<T&...
more »

2017-07-18 11:07 (3) Answers

Haskell: Monad transformers and global state

I'm trying to learn Haskell. I'm trying to write a programm that contains a "global state": Vars. I want to change a component of the state (e.g. var1) each time I call a function. The change can be a simple function on the components (e.g. +4). Also...
more »

2017-07-18 11:07 (1) Answers

Using Comonad Fix Combinators

So I've been experimenting with fixed points lately and have finally struggled through regular fixed points enough to discover some uses; now I'm moving onto comonadic fixed points and I'm afraid I've gotten stuck; Here's a few examples of what I've...
more »

2017-07-18 08:07 (1) Answers

Haskell type not clear

One of the exercises I am trying has defined a function as follows: twice f x = f (f x) When I print the type of twice I see: Main> :t twice twice :: (a -> a) -> a -> a Not sure I understand the output here. So twice takes an input ...
more »

2017-07-18 05:07 (2) Answers

Haskell Persistent Database Primary Key

When using the following code, I don't want to use the default database key. Intead, I plan to generate a hashcode from a piece of information and use it as a key. How should I use such a key? share [mkPersist sqlSettings, mkMigrate "migrateAll"] [p...
more »

2017-07-17 11:07 (1) Answers

Haskell Monad State: gets and modify

I'm confused with the definitions of gets and modify in monad state. Somewhere says: gets: "Gets specific component of the state, using a projection function supplied". modify: Maps an old state to a new state inside a state monad. The old st...
more »

2017-07-16 20:07 (1) Answers

Syntax of where block

I'm reading Programming in Haskell by Graham Hutton and it gives the following code in Chapter 13: import Control.Applicative import Data.Char {- some code omitted -} newtype Parser a = P (String -> [(a, String)]) item :: Parser Char item = P ...
more »

2017-07-16 08:07 (2) Answers

Haskell how to make a list of results

i am trying to solve my homework, but have no Idea how. pls help me Write a method which generates the following list from a function f and a starting value x: [x, f ^ 1 (x), f ^ 2 (x), f ^ 3(x)...] f^n(x) is the n-time application of f to x...
more »

2017-07-15 20:07 (2) Answers

Multiple .ghci Files

I have a .ghci file with configurations for a Haskell project in the directory Project. When I run ghci from the Mac terminal in the directory Project, ghci loads both the project's Project/.ghci file and the home directory ~/.ghci file. Is there a m...
more »

2017-07-15 17:07 (1) Answers