Haskell is an advanced functional programming language, featuring strong static typing, lazy evaluation, extensive parallelism and concurrency support, and unique abstraction capabilities.
1
vote
1answer
18 views
Parse JSON with fieldnames that contain reserved keywords
I'm trying to parse the following JSON with aeson.
{
"data": [
{
"id": "34",
"type": "link",
"story": "foo"
},
{
"id": ...
0
votes
1answer
35 views
output a value in Haskell, with a default in case its type is not an instance of Show
I tried to debug some Arrows and this is really hard. I end up sticking trace here and there, but it really wants a Show instance as its argument, which limits its uses. Is there any way to show ...
0
votes
0answers
28 views
Dead code and/or how to generate a cross reference from Haskell source
I've got some unused functionality in my codebase, but it's hard to identify. The code has evolved over the last year as I explore its problem space and possible solutions. What I'm needing to do is ...
1
vote
2answers
44 views
Haskell main function doesn't print anything after it is run
I have a simple module like this:
module Main where
import Semantic
main = do
let result = linearize []
print result
After I click on the .hs file, It only says that modules are loaded ...
0
votes
1answer
29 views
Haskell QuickCheck generate random data for function with many input variables
I have a function with the following type signature
rndListIndex :: Double -> Double -> Double -> Double
rndListIndex maxIdx r1 r2 = …
the first input should be a value coming from a ...
0
votes
0answers
43 views
How to get a SHA-1 digest of a X509 certificate with HsOpenSSL?
I'm writing a web server that accepts SSL connections and calculate a SHA-1 hash of client certificates:
import OpenSSL (withOpenSSL)
import OpenSSL.Session as SSL
import OpenSSL.X509 as X509
import ...
0
votes
4answers
76 views
Haskell - converting a list of letters into a word (and removing speech marks)
Does anyone know of a way in Haskell to convert something in the form
["w","o","r","d"]
into
word
I have just finished my very first programme (an RSA encryption) and the output at the moment is ...
3
votes
1answer
94 views
encoding binary numerals in lambda calculus
I have not seen any mention of binary numerals in lambda calculus. Church numerals are unary system.
I had asked a question of how to do this in Haskell here: How to implement Binary numbers in ...
1
vote
2answers
62 views
Simulate a where in scheme with defmac
I'm actually faced to a problem in Scheme. And I just don't have any idea about how to solve it. It is pretty simple to understand and I guess kind of easy for any Scheme expert. I just have to ...
0
votes
1answer
44 views
Getting data out of rawQuery using Conduits
I admit I do not really understand Conduits very well given my limited Haskell knowledge. So appreciate if someone can guide me on how to accomplish this task: I would like to take the output of a ...
2
votes
1answer
127 views
Haskell Data.Binary: Shouldn't this be lazy? And how do I make it lazy?
I want to process a couple of hundred binary data chunks ("scenarios") for a Monte Carlo simulation. Each scenario consists of 1 million floats. Here's how I create a dummy binary file for the ...
0
votes
0answers
31 views
Static Routes in Custom Fields in Yesod
I'm working on a custom field used to pick datetimes in Yesod (stored as UTCTime). It uses Trent Richardson's timepicker. I actually have it working already. The only problem is that I have the static ...
2
votes
3answers
99 views
Is it possible to reuse a monad composition function if one of the monads is wrapped inside a monad transformer?
Let's say I have function that composes two monad actions:
co :: Monad m => m a -> m a -> m a
You can think of co as a higher order function that describes how two monadic actions may ...
3
votes
4answers
156 views
What is the best way to store and sort rectangular data in Haskell?
I have a handful of ASCII files containing around 17 million lines in total, and within each/most lines is a fixed 36-byte identifier. So my data is rectangular: I have a lot of rows of fixed width. ...
3
votes
2answers
80 views
Netwire - how to construct a wire that produces positions, bouncing of walls?
Using netwire-4.0.7
As the question title says, I'm trying to create a wire that produces positions (moving the position with a certain velocity in each step), "bouncing" off other objects. The ...
0
votes
1answer
82 views
Haskell couldn't match expected type, Weird behaviour
I have a module which looks like this:
module Network where
import Prelude hiding ((==))
import Sort
import Message
data Pair = Conn Loc Loc | Disconn Loc Loc deriving(Show,Eq)
data NC = EmpNC | Inn ...
10
votes
1answer
125 views
pattern matching of the form: Option{..} <-
What is this form of pattern matching called:Option{..} <- ..., e.g. as it is used here:
data Option = Option { cabal :: Maybe String , noStylish :: Bool }
...
main = do
Option{..} <- cmdArgs ...
1
vote
3answers
102 views
Overload built in function in Haskell
In Haskell, how can one overload a built in function such as !!?
I originally was trying to figure out how to overload the built in function !! to support by own data types. Specifically, !! is of ...
3
votes
1answer
85 views
Is type equality preserved across application in Haskell?
In haskell, does s k v ~ s1 k1 v1, where s :: * -> * -> *, imply that k ~ k1, v ~ v1, or s ~ s1? If not, why doesn't it?
I encountered this when writing some experimental code, a small piece of ...
3
votes
2answers
212 views
Haskell Vector performance compared to Scala
I have a very simple piece of code in Haskell and Scala. This code is intended to run in a very tight loop so performance matters. The problem is that Haskell is about 10x slower than Scala. Here it ...
0
votes
3answers
110 views
Recursion confusion in Haskell
I hope someone can help figure out where my error lies. Calling g 3 4 0 2 (M.empty,0) [], I would expect [[2,1,0,1]] as a result. Instead, I'm seeing [[2,1,0,1],[2,1,0,1]].
The program is supposed ...
6
votes
0answers
114 views
Haskell type-safe space usage
I really like Haskell, particularly it's strong type system. When I get Haskell programs to compile, they're generally bug free, or at least very close to it.
However, main problem with Haskell is ...
3
votes
2answers
129 views
Why are type instances (a->a) and (a->a->a) conflicting in GHC 7.8?
The hmatrix package contains the following type families code:
type family BoundsOf x
type instance BoundsOf (a->a) = Int
type instance BoundsOf (a->a->a) = (Int,Int)
On GHC 7.6, this ...
4
votes
2answers
78 views
Is there a way to union type constraints?
In Haskell, is there a way to OR together several type constraints, such that the union is satisfied if any one of them are satisfied?
For example, suppose I had a GADT parameterized by a DataKind, ...
1
vote
2answers
48 views
Double Quotes in Single Quotes
I need to put json in an html attribute like so:
<video id="video1"
class="video-js vjs-default-skin"
width="640" height="480"
data-setup='{"controls" : true, "autoplay" : false, "preload" : ...
3
votes
2answers
123 views
Does this monadic Haskell function already exist (or is a simple combination of known functions)?
I'm a relative beginner at Haskell, but with plenty of background in Mathematics, algebra in particular, so statements like "A monad is a monoid in the category of endofunctors" are not a problem for ...
0
votes
0answers
128 views
Haskell or Scala for AngularJS backend [on hold]
I would like to code an AngularJS app. Should I use Haskell or Scala as a backend? And what framework/library? It will only read data from SQL db, do some calculations and serve them as JSON. No other ...
7
votes
1answer
183 views
Why is there a 1000x performance difference between two versions of merge sort in haskell
EDIT:
It turns out the slow version is actually an insertion sort O(n^2) rather than a merge sort O(n log n) explaining the performance issue. I thought I'd save future readers the pain of wading ...
4
votes
2answers
89 views
How to do complex IO processing and implicit cache in Haskell?
In bigger applications there are very often multiple layers of IO caching (Hibernate L1 and L2, Spring cache etc.) which usually are abstracted so that caller needs not to be aware that particular ...
4
votes
1answer
82 views
Is there a principled way to compose two monad transformers if they are of different type, but their underlying monad is of the same type?
Not much I can do to expand the question. But here is a use case: let's say you have two monad transformers, t and s, transforming over the same monad m:
master :: (MonadTrans t, Monad m) => t m a ...
4
votes
3answers
190 views
How to implement Binary numbers in Haskell
I have seen the following data constructor for Church numerals
data Nat = Zero | Succ Nat deriving Show
But this is unary numbers.
How do we implement a data constructor for Binary numbers in ...
1
vote
2answers
160 views
Why creating and disposing temporal ByteStrings eats up my memory in Haskell?
Here is a code which creates 1M Int numbers and put them in a list.
main = do
let l = [1..1000000]
putStrLn $ show $ sum (foldl (\aux p -> p:aux) [] l)
(I know it could be more optimal (sum ...
10
votes
4answers
321 views
Is it possible to lazily traverse a recursive data-structure with O(1) memory usage, tail-call optimized?
Let's say that we have a recursive data-structure, like a binary tree. There are many ways to traverse it, and they have different memory-usage profiles. For instance, if we were to simply print the ...
7
votes
2answers
177 views
Efficiently implementing equal? in Scheme without direct access to pointer values
I am implementing R7RS-small Scheme and I have encountered the following problem with the implementation of equal?: (as should be obvious) equal? tests value equality, and it furthermore is able to ...
1
vote
2answers
84 views
Exception: Prelude.last: empty list in Haskell solving 8-queens?
I'm solving the 8-queens problem in Haskell using only basic functions nothing fancy
this is the code:
queens = ...
1
vote
1answer
90 views
Haskell: why catch is not working?
I am trying to read an Int from the input and managing a bad input from the user.
This a piece of code that does the job but it seems it is not working...
asknumplayers = do {
putStr "Please the ...
2
votes
0answers
49 views
How to use detailed-0.9 in cabal testing
I'm having a surprising amount of difficulty getting the unit tests to run under cabal. I've copied the test code verbatim from the cabal documentation, with the exception of changing the module name
...
0
votes
3answers
133 views
Polymorphic return type
A function reads ID from a stream of bytes. It knows the size of id - can be 4 or 8 bytes. How to make the return type polymorphic?
(Pseudocode:)
class (Integral a) => IdSize a where
...
0
votes
1answer
83 views
Access constructor name and arguments
I'm going to override the equal class for Dynamic data type in this way:
instance Eq Dynamic where
x==y = dynamicEq x y
dynamicEq :: Dynamic -> Dynamic -> Bool
dynamicEq x y = ConstrName x ...
0
votes
2answers
148 views
8 queens unknown error in haskell
This function isn't terminating! I'm trying to generate all possible safe combinations on an eight by eight chessboard for eight queens. I'm not sure what's going wrong. My code is below. The board is ...
1
vote
1answer
91 views
Specialization of polymorphic functions
In his talk “Classes, Jim, but not as we know them” Simon Peyton-Jones talks about how type classes are implemented in GHC by having polymorphic functions taking an extra parameter that is a ...
2
votes
1answer
103 views
haskell io stream memory
I try to parse large log files in haskell. I'm using System.IO.Streams but it seems to eat a lot of memory when I fold over the input. Here are two (ugly) examples:
First load 1M Int to memory in a ...
2
votes
1answer
84 views
Monad transformers: IO and state
This question is close to ground covered elsewhere, but I haven't found anything that addresses it specifically (at least not in a way that I'm able to understand).
I'd like to update state in a way ...
1
vote
1answer
44 views
Stackoverflow exception when comparing two dynamic types
I have defined a data type Loc which can accept Dynamics in the constructor. Moreover I need to compare Loc datatypes using == operator. So I came up with something like this:
data Loc = UnknownLoc | ...
2
votes
2answers
58 views
Insert a character into parser combinator character stream in Haskell
This question is related to both Parsec and uu-parsinglib. When we write parser combinators, they process characters streams from compiler. Is it somehow possible to parse a character and put it back ...
2
votes
1answer
136 views
Haskell: how to get rid of the memory leak
I was trying "all possible" tricks I came across the internet, with "all possible" combinations of !, seq, deepseq, ... but I could not find the way to suppress the leaking of memory in the following ...
8
votes
0answers
97 views
Profiling Template Haskell
I have a TH-heavy file which takes around 30 seconds to compile. What are some techniques I can use to help debug the performance of my Template Haskell?
1
vote
1answer
69 views
Haskeline: Implementing `MonadException` instance for `ReaderT r (StateT s m)` stack [duplicate]
Let's say I have the following monad transformer stack (r and s left as () for simplicity),
newtype MyMonad m a = MM (ReaderT () (StateT () m a)
If I want to use this as a base monad for ...
1
vote
3answers
181 views
Why encode function in data type definition?
I find it hard to get the intuition about encoding function in data type definition. This is done in the definition of the State and IO types, for e.g.
data State s a = State s -> (a,s)
type IO a ...
1
vote
1answer
74 views
Learning Haskell Parsec and dealing with optional Parsers
I'm redoing an old homework assignment for fun to learn how to use Parsec and I'm having trouble structuring my parsers for Exits (and the included datatype). So first we get a file with a list of ...