Bidirectional arrow

I'm trying to capture a symmetrical data processing pipeline using arrows, and was wondering if bidirectional composition is possible. Control.Arrow exposes the following -- | Left to right composition (>>>) :: Category cat => cat a b -> ca

GADT argument is not used for typeclass resolution

Consider the following code data Foo f where Foo :: Foo Int class DynFoo t where dynFoo :: Foo f -> Foo t instance DynFoo Int where dynFoo Foo = Foo obsFoo :: (DynFoo t) => Foo f -> Foo t obsFoo = dynFoo useDynFoo :: Foo f -> Int useDynFoo (ob

How to use QuickCheck to test if a function ends?

I would like to use QuickCheck to test a function to make sure it terminates (no infinite recursion, no exceptions thrown, etc.). This is what I do at the moment: f :: Int -> Int -> Int prop_fTerminates :: Int -> Int -> Bool -- say prop_fTermi

How to separate a flow of `1`s and` 2`s in groups?

Imagine I have a really long file like this: 1 1 1 1 2 2 2 2 1 1 1 1 2 2 1 1 2 2 ... I'm interested in separating and performing computation on each group of consecutive 1s along with the consecutive 2s that come immediately after it. However, the pr

Haskell / GHC: Deconstruct a constructor incorrectly?

Here's a specific case of the general question I'm really asking: Suppose I'm in a performance critical section of code and I've received a value x :: Maybe Int I know it's a Just Int and not a Nothing, but due to code out of my control, I can't arra

Symbolic Theory Proving Using SBV and Haskell

I'm using SBV (with Z3 backend) in Haskell to create some theory provers. I want to check if forall x and y with given constrains (like x + y = y + x, where + is a "plus operator", not addition) some other terms are valid. I want to define axiom

Alternative I / O error for & lt; | & gt;

I am using the operator <|> for: import qualified Data.ByteString.Lazy as B import Network.HTTP.Conduit (simpleHttp) import Data.Aeson import Data.Maybe data FooBar = FooBar { name :: !Text, surname :: !Text } deriving (Show,Generic) instance FromJS

get scan error on input '=' error (haskell)

my function append takes a list of lists [[a], [b,c], [d,e]] and returns a single list [a,b,c,d,e]. I wrote this in a file so i didn't have to use "let" but i still get parse error on input '='. can anyone help? thanks append :: [[a]] -> [a]

Matrix Indexing Lens Out of Network and Index Lenses

This is a simpler version of Using lens for array indexing if both array and index are in State as I have resolved some issues. I'm not sure if I should delete the original or edit it in place. Given {-# Language TemplateHaskell #-} {-# Language Rank

the statement & lt; - do not compile for Maybe

import Network.HTTP.Conduit import qualified Data.HashMap.Lazy as LHashMap import Network.HTTP.Types getJSONObject :: String -> IO Object --............. main = do jsonObject <- getJSONObject "example.com" String a <- LHashMap.lookup &q

Code gets slower as more canned berries are allocated

Edit: It turns out that things generally (not just array/ref operations) slow down the more arrays have been created, so I guess this might just be measuring increased GC times and might not be as strange as I thought. But I'd really like to know (an

Haskell type error (Int -> Bool function parameter)

I'm trying to recursively find the ith positive integer for which the predicate is true. I need to keep it general for every function. ithTrueValue :: (Int -> Bool) -> Int-> Int ithTrueValue func i | i < 1 = error "Integer MUST BE greater

Filter a list of haskell

This is the code i have: data Review = Review { artiest :: String, score :: Integer, tour :: Tour, datum :: String, plaats :: String, soortLocatie :: Locatie, topSongs :: [String] } deriving (Eq, Ord, Show) getBestLoc [] beste = beste getBestLoc (x:x

I can not have the correct type definitions

I'm trying to implement a simple function, that does the following: it takes a tuple in the following format (Int, a) and if the first element is 1 (ex: (1, a)) then it returns a, else it returns a tuple. This should be based on the CounterElem data

Cabal - Expose all modules while building the library

Is it possible to tell Cabal to expose all modules while building a library? Right now I have to provide very long list of modules in the Exposed-modules cabal configurtion file section.You have to list all modules in the cabal configuration file. In

do not force the evaluation

So I have my haskell program that looks something like this: main = do secondData <- loadSecondBars "output.data" putStrLn $ "Generated Second Data " ++ (show $ length secondData) let tenMinBars = secondData `seq` generateBars (barS

Haskell Monad.Writer

I am writing a logger for a sorting function like this: bubble :: (Ord a) => [a] -> Writer [String] [a] bubble (x:y:ys) | x > y = do tell [show x ++ " why does this not work"] y:bubble(x:ys) | otherwise = do tell [show y ++ " is a

Syntax shorter for cases in Haskell?

Say I have something silly like this: data SomeType = Unary Int | Associative SomeType | Binary SomeType SomeType some_func :: SomeType -> Int some_func s = case s of Unary n -> n Associative s1 -> some_func s1 Binary s1 s2 -> some_func s1 + s

Convert type a to character

I have data Dictionary a = Empty | Branch (a, Bool, Dictionary a) (Dictionary a) deriving (Ord, Eq) instance Show (Dictionary a) where show = showDict showDict (Branch (val, e, dict) dict2) = "My dict is : " ++ val I know it is definitely wrong

Haskell: Function to determine the arity of the functions?

Is it possible to write a function arity :: a -> Integer to determine the arity of arbitrary functions, such that > arity map 2 > arity foldr 3 > arity id 1 > arity "hello" 0 ?It's easy with OverlappingInstances: {-# LANGUAGE Flex

Haskell: Get and remove from the list

I'm having a problem with getting and dropping the first value from list in the recursive function. Here is the code: removeDuplicates a u = [if a == [] then u else removeDuplicates newA newU | let newU = (head a):u | let newA = tail a] And error: Il

Evaluate buffer in ghci or hugs via Emacs

Using sml-mode in Emacs I have been able to send my buffer contents directly to an inferior SML process using C-c C-b. Now I want to do the same thing only with Haskell. Haskell-mode does not seem to support this, so I'm wondering: What is the right

Is there an EDSL haskell for writing lexers?

Mixing the lexer and parsing phases in one phase sometimes makes Parsec parsers less readable but also slows them down. One solution is to use Alex as a tokenizer and then Parsec as a parser of the token stream. This is fine but it would be even bett

Haskell - Merge Sort, sort words and numbers

I've written a merge sort in Haskell, it works when using numbers but not with words, and I thought it would. I just get "Not in scope" when using words and letters. What am I doing wrong? Here's my code: merge :: Ord a => [a] -> [a] ->