Understanding the MonadIO Laws

From source: module Control.Monad.IO.Class ( MonadIO(..) ) where -- | Monads in which 'IO' computations may be embedded. -- Any monad built by applying a sequence of monad transformers to the -- 'IO' monad will be an instance of this class. ...
more »

2017-09-14 22:09 (1) Answers

Alternating series using Haskell

I am trying to use Haskell to read in a list and perform an alternating series, so starting with the first element adding every other and subtracting every other from the second element. For instance [1, 2, 3, 4] would be 1-2+3-4=-2. I thought I had...
more »

2017-09-14 21:09 (2) Answers

Parsec start-of-row pattern?

I am trying to parse mediawiki text using Parsec. Some of the constructs in mediawiki markup can only occur at the start of rows (such as the header markup ==header level 2==). In regexp I would use an anchor (such as ^) to find the start of a line. ...
more »

2017-09-14 20:09 (2) Answers

How does Foldable.foldl work on Num a => a

In LYAH, there is a piece of code that looks like this. data Tree a = Empty | Node a (Tree a) (Tree a) deriving (Show, Read, Eq) instance F.Foldable Tree where foldMap f Empty = mempty foldMap f (Node x l r) = F.foldMap f l `mappend` ...
more »

2017-09-14 18:09 (1) Answers

Combining two list comprehensions Haskell

I'm trying to calculate the first triangle number with 501 divisorsin Haskell. I already made two list comprehensions, one listing all the triangle numbers and one listing all divisors of a given number. Now I want to make one big list with all value...
more »

2017-09-14 17:09 (1) Answers

Matching Integral with Int (Haskell)

I'm new to Haskell and I'm trying to get the length of a number in base 10 so I created length' function: length' :: (Integral a) => a -> a length' a = length $ show a But Haskell gives me "Couldn't match type" error because length returns I...
more »

2017-09-14 15:09 (2) Answers

Using isUpper, isLower, and isDigit in Haskell

I am having trouble with how to use isUpper, isLower, and isDigit. Specifically I am trying to take a string and return a list of tuples for each character in the string containing three Bool values for if the character is an uppercase letter, a low...
more »

2017-09-14 08:09 (2) Answers

Partial application of type synonyms

I'm having trouble with unsaturated type synonyms in the following example: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE LiberalTypeSynonyms #-} module TypeFamilyHackery where data T k v a = T type family CollectArgTypes arr where CollectArgTypes...
more »

2017-09-13 18:09 (1) Answers

Where to find chunks in haskell?

I'm trying to follow this tutorial: https://wiki.haskell.org/Tutorials/Programming_Haskell/String_IO. In the last part 7 Extension: using SMP parallelism I copy the code but it fails to compile with this error message /home/dhilst/parallelspell.hs:...
more »

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

Quickcheck specification DSL

I want to create a human readable DSL which non-haskell programmer could understand for creating specifications for black-box testing of external systems. And I wonder if something like this is possible to do in Haskell. action = readProcess "sleep...
more »

2017-09-12 16:09 (0) Answers

Haskell :: Recursion for List of Tuples

I am mapping a tuple and managed to make it work for a single tuple (a, a). But when I've changed the tuple to [[(a, a)]], then it says that "couldn't match the expected type of [(a, a)] with (a, a). mapTuple :: (a -> b) -> [[(a, a)]] ->...
more »

2017-09-12 14:09 (2) Answers

Catamorphism in F#

I'm reading the wikipedia article about catamorphisms and for the moment I was able to reproduce the Haskell examples in F# except for this part : type Algebra f a = f a -> a -- the generic f-algebras newtype Fix f = Iso { invIso :: f (Fix f) } ...
more »

2017-09-12 11:09 (1) Answers

Constrained heterogeneous list

I searched Hackage and couldn't find anything like the following but it seems to be fairly simple and useful. Is there a library that contains sort of data type? data HList c where (:-) :: c a => a -> HList c Nil :: HList c All the HList...
more »

2017-09-12 03:09 (3) Answers