Convert wav audio format ByteString to Floats

I'm working on sensor data that is stored in .wav files. The samples represent floating point numbers between -1 and 1. I'm reading samples from the .wav file as ByteStrings and I need a way to convert this ByteString to a Float. So I'm looking for...
more »

2017-01-11 21:01 (2) Answers

Creating filter conditions based on list elements

I'm interested in creating a filter, whose conditions depend on an input list. Specifically, I want to define the filter such that it checks whether a number is divisible by any number in my input list. So for a single element that would be: my_filt...
more »

2017-01-11 17:01 (1) Answers

Page Anchors In Yesod

Normally you can specify an anchor on a page such as "index.html" with code such as: <a href="#anchor">Link Text</a> You can then jump to that anchor when the page is displayed by including it in the path: http://example.com/index.htm...
more »

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

cabal: haskell-gi-base refuses to install

When I try $ cabal install gi-cairo (One of the long list of dependencies to install leksah) I get the following error: Resolving dependencies... Configuring haskell-gi-base-0.9... Building haskell-gi-base-0.9... Failed to install haskell-gi-base...
more »

2017-01-10 15:01 (0) Answers

How to sort custom Type by String

How can I sort animals by their name? Names are represented by String values. data Animal = Cat String | Dog String | Fox String deriving (Show) testAnimals = [(Dog "c"),(Fox "a"),(Cat "b")] sortAnimalsByName :: [Animal] -> [Animal] sortAnimals...
more »

2017-01-10 12:01 (3) Answers

Avoiding class constraint on type level naturals

I am using the Nat type in from the GHC.TypeLits module, which admittedly says the programmer interface should be defined in a separate library. In any case, the GHC.TypeLits has a class KnownNat with a class function natVal which converts a compile ...
more »

2017-01-10 05:01 (1) Answers

What does Cons and :-: mean in Haskell?

In LYAHFGG, one chapter says that list is defined as: data List a = Cons a (List a) deriving (Show, Read, Eq, Ord) I understand what most of this means apart from Cons. When I try :t Cons and :i Cons in ghci I get a not in scope error. Later on i...
more »

2017-01-10 00:01 (2) Answers

Match data without pattern matching

How can I check if a variable is of a certain data type without pattern matching? data MyData = A | B | C char deriving (Eq) -- This works. isA :: MyData -> Bool isA x = x == A -- This generates a compile error. isC :: MyData -> ...
more »

2017-01-10 00:01 (2) Answers

Practical applications of Rank 2 polymorphism?

I'm covering polymorphism and I'm trying to see the practical uses of such a feature. My basic understanding of Rank 2 is: type MyType = ∀ a. a -> a subFunction :: a -> a subFunction el = el mainFunction :: MyType -> Int mainFunction...
more »

2017-01-09 23:01 (2) Answers

Mixing fmap and bind (>>=)

In Haskell, when I have to mix calls to fmap/<$> and >>=/=<<, I invariably end up with lots of parenthesis. For example, here I'm calling listDirectoryAbs dir :: IO [String] and then chaining a series of filter and filterM, ending ...
more »

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

Queue with balanced lists in haskell

I'm trying to write a definition for balanced lists in haskell. QueueA should be the queue with balanced lists: module QueueA where import Queue data QueueA a = QA [a] [a] instance Queue (Queue a) where empty = QA [] [] (|>) (QA a b)...
more »

2017-01-09 17:01 (2) Answers

GHC optimization

The two Haskell functions below seems to differ only by whether the index variable is implicit or explicit but the difference in performance is by two orders of magnitude. This function takes about 0.03 seconds to calculate mfib 30: let mfib = (map...
more »

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

avoiding recompilation when types don't change

I have a large Haskell project with many packages built with stack. I have long recompilation times when I make trivial changes in a core model or some configuration data without changing any types. If this were C, I would have to only recompile the...
more »

2017-01-09 00:01 (0) Answers

seq stops as soon as it reaches a constructor

RWH explains that seq stops as soon as it reaches a constructor. case1 = 1:repeat undefined `seq` "OK" case2 = (undefined,undefined) `seq` "OK" We have 1:repeat undefined = (:) 1 (repeat undefined) (undefined,undefined) = (,) undefined undefined...
more »

2017-01-08 20:01 (2) Answers

Install local library

How can I "install" a local (ie it is on my hard-drive, not on the internet) .hs file to use it across multiple programs? Specifically, if I edit the library, those edits should be available to all programs, so no copy-pasting the library into every ...
more »

2017-01-08 17:01 (1) Answers

Strange behaviour of list comprehensions

I'm learning basics of Haskell and trying to solve project Euler's simple tasks: find largest palindrome of 3 digit numbers (100.999). I wrote this code: palindrome = maximum $ filter (\a -> reverse a == a) $ m...
more »

2017-01-08 16:01 (1) Answers