Why can't Haskell function return a list

What is wrong with that: partin a = [floor a, a-floor a] Error : <interactive>:342:1: error: • Ambiguous type variable ‘a0’ arising from a use of ‘print’ prevents the constraint ‘(Show a0)’ from being solved. P...
more »

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

How do I prevent GHCi from "crashing" from this?

I tried running this code, and it ended up making GHCi unusable. Meaning, the command line (Windows) ended up not responding to any input and simply displaying an empty line. Prelude> b = ["Empty", "Discrete", "Distinct", "Defiant", "Useful", "Go...
more »

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

How do I correctly use toLower in Haskell?

I've recently started to learn Haskell and wanted to convert something to lowercase. I looked up the function "toLower", but it doesn't seem to work. Prelude> import Data.Text Prelude Data.Text> toLower "JhELlo" <interactive>:2:9: error...
more »

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

Haskell type mismatch Int and [Int]

I'm a beginner to Haskell. I'm trying to create a function which has two parameters: a character and a string. This function is supposed to go through the string and check if the character given is in the string, and then return a list of integers re...
more »

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

How does laziness affect benchmarking in Haskell?

This question is related to the following question : How to force evaluation in Haskell? I want to benchmark the algorithm quicksort for a list. For this I have made a certain number of files which have random numbers in them. Here is the relevant ...
more »

2017-10-04 14:10 (1) Answers

"takeWhile (<= (maxBound :: Word8)) primes" hangs

Today I was up to find out how many prime numbers there are that fit the bounds of Word8, but this most trivial task gave me an unexpected... absence of result. λ import Data.Numbers.Primes λ import Data.Word λ takeWhile (<= (maxBound :: Word8...
more »

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

Correct Usage of >> in Haskell

Just now being introduced to monads in Haskell and hit something of a roadblock with >>. >>= makes sense to me, as I can get the following out of Prelude: Prelude> Just 1 >>= (\ x -> Just (x+1)) Just 2 My understanding is ...
more »

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

Does each type have a unique catamorphism?

Recently I've finally started to feel like I understand catamorphisms. I wrote some about them in a recent answer, but briefly I would say a catamorphism for a type abstracts over the process of recursively traversing a value of that type, with the p...
more »

2017-10-04 11:10 (1) Answers

Is default Setup.hs beneficial?

stack new usually creates a default Setup.hs file. I removed it from a project and it still builds alright for any lts resolver down to lts-2. It also passes cabal check at least for cabal version 1.24. (Though not for cabal 1.22.) Can I conclude fr...
more »

2017-10-04 08:10 (0) Answers

Generate n-ary binary tree in haskell

I try to create random trees from this structure: data Tree a = Leaf a | Funktion (Tree a) (Tree a) | Lambda (Tree a) deriving (Show) The problem I have is that I don't even know how to generate a tree with the...
more »

2017-10-03 23:10 (2) Answers

Type error in list comprehension

I am new to Haskell and I encountered a error like this. learnHaskell.hs:1:51: error: * No instance for (Enum [t0]) arising from the arithmetic sequence `1 .. 10' * In the expression: [1 .. 10] In a stmt of a list comprehension: radius <- [...
more »

2017-10-03 23:10 (1) Answers

Update a row with specific ID in Esqueleto

I can change a field of a row with entryId in Esqueleto like this: update $ \entry -> do set entry [ EntryFoo =. val bar ] where_ (entry ^. EntryId ==. val entryId) However, writing it all the time gets annoying. I'd like to be able t...
more »

2017-10-03 21:10 (1) Answers

Implementation of tree-traversal: pre-order

I have to implement a pre-order tree traversation: The result of (Knoten 'A'(Blatt 'B')(Blatt 'C')) have to be ['A','B','C'] This is my Code but there was a mistake I am not able to find: data Baum a = Blatt a | Knoten a ...
more »

2017-10-03 21:10 (0) Answers

Making Haskell Monads

I'm trying to create a very simple monad in Haskell. The monad does nothing special but holding a counter as state. module EmptyMonad ( EmptyMonad ) where import Control.Monad data EmptyMonad a = EmptyMonad { myValue :: a , myState :: Int ...
more »

2017-10-03 20:10 (1) Answers

const function of const function in haskell

We have defined the following : const a x = a Now my question : Why does the defined "variable" a in the following example evaluate as a number with the value 5 ? a = const 5 const Because if we look at the first part, namely the "const 5", we ...
more »

2017-10-03 19:10 (2) Answers

Servant Client Query

I am getting this error: No instance for (Show (ClientM Bittrex)) arising from a use of ‘print While building the following code: {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeOperators #-} module Main where impo...
more »

2017-10-03 19:10 (0) Answers

Hakyll clean and build still has caching error

I execute the following: $ stack exec site clean Removing _site... Removing _cache... Removing _cache/tmp... And then: $ stack exec site build Initialising... Creating store... Creating provider... Running rules... Checking for out-of-date ...
more »

2017-10-03 06:10 (0) Answers

Haskell parse expression

Hi I got a code like this: data Digit = Zero | One | Two | Three | Four | Five | Six | Seven | Eight | Nine deriving (Eq, Show) data Number = Single Digit | Many Digit Number deriving (Eq, Show) data Expr = Lit Number ...
more »

2017-10-03 00:10 (1) Answers

Can not find module after installing it

I am trying to install "threepenny-gui", I simply do it by cabal install threepenny-gui It is a school project that I have to use it and you can find the start code here. After I have installed it and run Calculator.hs without changing anything ...
more »

2017-10-02 23:10 (0) Answers

Work of 2 functions

I am converting number from octal to decimal. I get number as [Char], so I decided to convert it to [Int] first, then I multiply every digit by the corresponding power of 8. Finally, I planned to use sum and get my decimal number. How can I make 2 fu...
more »

2017-10-02 19:10 (2) Answers

How to make type variables less rigid?

I had been trying to implement automatic differentiation, from this post Here is what I had, which worked so far: data DX a = DX { val :: a, dx :: DX a } instance Num n => Num (DX n) where fromInteger x = DX (fromInteger x) 0 DX x₀ x' + D...
more »

2017-10-02 16:10 (0) Answers

An example for chronomorphism

I don't understand how can I create some example with chronomorphism. I know about hylomorphism (cata, ana) also I know about histo and futu. But I don't realize some example for chronomorphism (maybe some behavior as in Tardis monad). Also relate...
more »

2017-10-02 14:10 (0) Answers

Installing a package outside current resolver

I'm using stack lts-9.0 snapshot, which includes process-1.4.X. Due to some problems with this version, I would like to use process-1.6.1.0. Adding this version to extra-deps does not seem to be enough: extra-deps: - process-1.6.1.0 since this wil...
more »

2017-10-02 11:10 (1) Answers