Category "haskell"

Proving a simple list function applied four times is the identity

The following video contains a mathematical card trick due to Colm Mulcahy: https://www.youtube.com/watch?v=dHzUQnRjbuM The key operation in the trick is define

How does Haskell "desugar" getline in this do block?

I've read a few books on Haskell but haven't coded in it all that much, and I'm a little confused as to what Haskell is doing in a certain case. Let's say I'm u

How to remove GHC 9.2.1 on Windows 10 that has been installed via chocolatey?

I have installed ghc 9.2.1 via chocolatey on Windows 10. I tried to remove it with choco uninstall ghc and it says that one package has been removed. But I can

Why isn't (b) of (a -> (b -> c)) the first parameter in the function definition but the second in type signature?

If first parameter is taken by the function first as function application is left-associative, for example: drop 2 [1,2,3,4] result: [3,4] is equivalent to (dr

Haskell Lenses: Difference of two HashSets in Folds

Given: f1, f2 :: Fold Box (HashSet Thing) how do I write a fold that focuses the Things that are in f1 but not in f2? It would (of course) be the same Box, but

how do I present number of spaces in haskell [duplicate]

I am just learning Haskell. I am trying to present a number of spaces using a variable. For example, if I have a function: function (a,x,b) I

What is the suggested way of setting up Haskell on Archlinux?

Long story short, I'd like some guidance on what's the (best) way to have Haskell work on Archlinux. By work I mean all, in terms of the ghci command line tool,

How to debug a stack process being 'killed'?

I'm compiling a haskell file with $ stack ghc --resolver lts-12.5 --package raw-strings-qq myscript.hs and execute it with $ ./myscript Killed $ on my Ub

Applicative in Haskell for single variable

I recently started learning Haskell and encountered a problem with the idea of Applicative. I need to make an implementation for newtype MyTriple a = MyTriple (

howto prebuild on gitpod with haskell and stack

I have checked out https://github.com/gitpod-io/template-haskell and merged samples for a book (haskell in depth) into my branch. Prebuilding has no effect, eve

Python fuctional style iterative algoritm?

In Haskell there is a simple list function available iterate :: (a -> a) -> a -> [a] iterate f x = x : iterate f (f x) In python it could be implemen

How to retrieve the bounding box of an object with cairo

I'm making drawings with the Haskell cairo binding and I want to align some object vertically. To do that, I need to know the width (the bounding box or partial

Applicative for a user defined type

I'm trying to write Applicative for this type data Choice a = ColumnA a | ColumnB a I wrote a Functor instance: instance Functor Choice where fmap f (Co

Defining new types in Haskell

I am pretty new to Haskell, and I was wondering if one can define new types that are defined by lists of other types. For example, I assume a string is defined

How can I write test cases for instances in Haskell

I have an instance of Num for a type I created called Vec: instance Num Vec where (+) (Vec x) (Vec y) = Vec (zipWith (+) x y) And I am trying to write a test

No instance for (Show (Double -> Double))

I have the following code which uses Newton's method to approximate the square root of some number. The problems is that when I run it, I get an error..What is

Mergeable with sum and product in type indices

Is there anything in Haskell resembling the following type class? class Mergeable (f :: Type -> Type -> Type) where merge :: f a b -> f c d -> f (

Making instance of Applicative

Still not a hundred percent shure how to make instances of the more complex types. Have this: data CouldBe a = Is a | Lost deriving (Show, Ord) Made an ins

Why is this Haskell code so slow compared to other languages?

As an exercise in learning Haskell I've written an interpreter for the CESIL language (an old, very basic, educational low level language). It works, but compar

Haskell-Find the shortest word in the list

minimumBy takes as the first parameter a function that should be used to compare two elements. comparing is a higher-order function that can be used to transfor