What is a good network graph library for language X?

I have noticed that a recurring question is: “What is a good network graph library for language X”. I have played with quite a few of the libraries and I can share my experiences with...

What is [] (list constructor) in Haskell?

I'm Having problems understanding functors, specifically what a concrete type is in LYAH. I believe this is because I don't understand what [] really is. fmap :: (a -> b) -> f a -> f b Is [],...

What is "lifting" in Haskell?

I don't understand what "lifting" is. Should I first understand monads before understanding what a "lift" is? (I'm completely ignorant about monads, too :) Or can someone explain it to me with...

Understanding Haskell's fibonacci

fibs :: [Int] fibs = 0 : 1 : [ a + b | (a, b) <- zip fibs (tail fibs)] This generates the Fibonacci sequence. I understand the behaviour of the guards, of :, zip and tail, but I don't understand...

Haskell: read input character from console immediately, not after newline

I've tried this: main = do hSetBuffering stdin NoBuffering c <- getChar but it waits until the enter is pressed, which is not what I want. I want to read the character immediately after user...

Haskell - What makes 'main' unique?

With this code: main :: FilePath -> FilePath -> IO () main wrPath rdPath = do x <- readFile rdPath writeFile wrPath x I got the following error: Couldn't match expected...

How to increment a variable in functional programming?

How do you increment a variable in a functional programming language? For example, I want to do: main :: IO () main = do let i = 0 i = i + 1 print i Expected output: 1

Saving the state of a random number generator in haskell

I'm currently using the Crypto.Random and Crypto.Random.DRBG Haskell libraries for generating random numbers. However, I find myself needing to store their states in some form of file (e.g. a .txt...

Depending on a local package in cabal

I've written a few packages containing some extra functions for dealing with common types that reflect the way I like to use them (for instance, I prefer to treat Bson documents as maps, rather...

Haskell: Detect current OS

I'm currently writing a Haskell package. I want it to behave differently on Windows and Unix. What is the most "correct" way to detect what OS my code is being compiled on? I did try using CPP and...

Why is this Haskell program so much slower than an equivalent Python one?

As part of a programming challenge, I need to read, from stdin, a sequence of space-separated integers (on a single line), and print the sum of those integers to stdout. The sequence in question...

Haskell/GHC 7.10.1/Leksah : What is the meaning of this Warning: "name ... found in source file but was not in scope"

I am using the Leksah IDE 0.15.0.1 and I get a warning when compiling the example package: "name ... found in source file but was not in scope". What is the meaning of this Warning ? I googled for...

How do I deal with many levels of indentation?

I am writing a script that has a very logically complicated loop: main = do inFH <- openFile "..." ReadMode outFH <- openFile "..." WriteMode forM myList $ \ item -> ... ...

Haskell version of Idris !-notation (bang notation)

I've had the luxury of learning a bit of Idris lately and one thing I've found extremely convenient is the !-notation, which let's me shorten monadic code inside a do block such as a' <- a b' <-...

Not in scope: `catch'

I am reading learn you a haskell for great good but i faced an error of Not in scope: `catch' when I read the exception section in input & output chapter here is my code: import System.Environment...

Kotlin prepend element

I am searching for Kotlin alternative to: (cons 1 '(2 3)) in lisp or 1 : [2, 3] in haskell or 1 :: List(2, 3) in scala, (which all result in sth like [1, 2, 3]) so I can prepend an...

Traversals as multilenses: What would be an example?

I'm currently working on understanding the lens library in detail by following the explanation in https://en.wikibooks.org/wiki/Haskell/Lenses_and_functional_references#The_scenic_route_to_lenses,...

How to convert a list of tuples into a regular list in haskell?

I'd like to convert a list of tuples (a,a) into just a list of as. This is what i have so far map (\(x,y) -> [x,y]) [(1,4),(2,5)] > [[1,4],[2,5]] but what i want is > [1,4,2,5]

Memoize multi-dimensional recursive solutions in haskell

I was solving a recursive problem in haskell, although I could get the solution I would like to cache outputs of sub problems since has over lapping sub-problem property. The question is, given a...

Power set using BST in haskell

I have implemented a Set datatype in Haskell using Binary search tree. I have not used any of the in-built functions nor imported any module. My set datatype is as follows: data Set a = Empty |...

Why Reader implemented based ReaderT?

https://hackage.haskell.org/package/transformers-0.6.0.2/docs/src/Control.Monad.Trans.Reader.html#ReaderT I found that Reader is implemented based on ReaderT using Identity. Why don't make Reader...

Can I compute a type's cardinality generically?

I'd like to have a type class that tells me how big various types are. data Cardinality = Finite Natural | Infinite class Sized a where cardinality :: Cardinality It's pretty straightforward to...

Two computationally different ways of computing the maximum of 3 numbers

Q) Write two different functions maximum1 and maximum2 that compute the maximum of three numbers. The built in max functions can't be used I have the following code, would this be considered...

Haskell data structure with O(1) indexing/updating and O(logn) cons

Currently I need an immutable data structure (indexed by Int) that has fast read and update (basically, effectively O(1)), but somewhat slower cons (such as O(logn)) is acceptable. Other...

Could std::ranges::views::transform one day support any functor?

std::transform from the <algorithm> header applies to ranges, and it is what "enables" us to use ranges as the functors they are (*in the sense of category theory*(¹)). std::transform is...

Intersection and difference function on sets using BST in haskell

I have implement the Set datatype using Binary search tree. My implementation is as follows:- data Set a = Empty | Node a (Set a) (Set a) I have also written some other functions such as...

Question about the Foldable Maybe instance

Source: Hutton, Graham. "Programming in Haskell" (p. 267) Show how the Maybe type can be made foldable and traversable, by giving explicit definitions for fold, foldMap, foldr, foldl and...

using Data.Map.map to sum values

I want to sum Doubles with the Data.Map.map function. So i want to have a function like this: sumTheDoubles :: Mapping.Map Char [(Char, Double)] -> Mapping.Map Char [(Char, Double)] I want to...

Is it possible to manually update the value of a Behaviour? (Functional Reactive Programming, Threepenny)

I really hope I haven't gone down a dead-end here. I have a Behaviour that gives the currently selected Color, and the current mouse coordinates, then carries out a task when the mouse is clicked....

Binding a Maybe within another monad to avoid case stairway of doom?

I'm fetching a user from a database with a key I'm fetching from an api (uid). The uid is a Maybe ByteString, and so I can either case check whether it's a Maybe and then run the Redis monad, or...