haskell

My use of Haskell's Text.JSON considered ugly?

What I am trying to do is really simple. I'd like to convert the following JSON, which I'm getting from an external source: [{"symbol": "sym1", "description": "desc1"} {"symbol": "sym1", "description": "desc1"}] into the following types: data Symbols = Symbols [Symbol] type Symbol = (String, String) I ended up writing the follo...

Haskell: Am I misunderstanding how Arrows may be used?

I wrote some toy code to play with the concept of Arrows. I wanted to see if I could write an Arrow which encoded the concept of a stateful function - giving a different value after different calls. {-# LANGUAGE Arrows#-} module StatefulFunc where import Control.Category import Control.Arrow newtype StatefulFunc a b = SF { unSF :: a ...

Disadvantages of Scala type system versus Haskell?

I have read that Scala's type system is weakened by Java interoperability and therefore cannot perform some of the same powers as Haskell's type system. Is this true? Is the weakness because of type erasure, or am I wrong in every way? Is this difference the reason that Scala has no typeclasses? ...

Cannot create apply function with static language?

I have read that with a statically typed language like Scala or Haskell there is no way to create or provide a Lisp apply function: (apply #'+ (list 1 2 3)) => 6 or maybe (apply #'list '(list :foo 1 2 "bar")) => (:FOO 1 2 "bar") (apply #'nth (list 1 '(1 2 3))) => 2 Is this a truth? ...

Function Balanced one or more parentheses

I want to define function called Balanced that takes string containing parentheses and returns true if the parentheses in this string are Balanced and False if not In Haskell Please ...

In Emacs, how to use align-regexp to align <- and = together

I've tried, with M-x align-regexp: <-|= (<-|=) \(<-|=\) \\(<-|=\\) And the ones with <- and = reversed. But none work? Example code as follows: (flags, params, errs) <- parseArgs <$> getArgs let options = foldr id [] flags -- Apply functions to list ...

Functions that look pure to callers but internally use mutation

I just got my copy of Expert F# 2.0 and came across this statement, which somewhat surprised me: For example, when necessary, you can use side effects on private data structures allocated at the start of an algorithm and then discard these data structures before returning a result; the overall result is then effectively a...

How to split a 110Mo file with Haskell

Hi I have a file which look like this index : label, index's value contain keys in the range of 0... 100000000 and label can be any String value, I want split this file which has 110 Mo in many slices of 100 lines each an make some computation upon each slice. How can I do this? 123 : "acgbdv" 127 : "ytehdh" 129 : "yhdhgdt" ... 989...

How does Haskell deal with documentation?

Any pattern&practise here for documentation in Haskell? Are there anything as elegant/handy as what Python does below? >>> help([].count) Help on built-in function count: count(...) L.count(value) -> integer -- return number of occurrences of value ...

optimization of a haskell code

Hi, I write the following Haskell code which take a triplet (x,y,z) and a list of triplets [(Int,Int,Int)] and look if there is a triplet (a,b,c) in the list such that x == a and y == b if it is a case i just need to update c = c + z, if there is not a such of triplet in the list I just add the triplet in the list -- insertEdge :: (In...

Why do you have to use both a compiler flag and a run-time flag to get multicore-support in Haskell?

The Haskell wiki shows that you need to both set a compilation flag and a run-time flag to get multi-core support. Why isn't using the library enough to get the correct behavior at compile time? Why can't the run-time executable detect it was compiled with -threaded and use all cores on the system unless otherwise specified? I think turn...

Haskell Parsec and Unordered Properties

I am trying to use Parsec to parse something like this: property :: CharParser SomeObject property = do name parameters value return SomeObjectInstance { fill in records here } I am implementing the iCalendar spec and on every like there is a name:parameters:value triplet, very much like the way that XML has a name:att...

Is Haskell's Network.Browser module like Perl's LWP or Python's mechanize?

The Network.Browser documentation says that the module supports the following: HTTP Authentication handling Transparent handling of redirects Cookie stores + transmission. Transaction logging Proxy-mediated connections. To me, it sounds like the beginnings of a browser that lets me crawl web pages, handling authenciation into web sit...

Haskell: split even and odd elements into tuple

I can't use high order functions. I just can't see to figure out how to do this. I am very new to haskell. It also has to be recursive. split :: [Int] -> ([Int],[Int]) split xs = I am given this to start with. I honestly don't even know where to start with this problem. Examples: split [] ([],[]) split [1] ([1],[]) split [1,2,3...

Haskell: Recursion with a polymorphic equality function

Ok so we have not learned polymorphic functions yet, but we still have to write this code. Given: nameEQ (a,_) (b,_) = a == b numberEQ (_,a) (_,b) = a == b intEQ a b = a == b member :: (a -> a -> Bool) -> a -> [a] -> Bool I added: member eq x ys | length ys < 1 = False | head(ys) == x = True | otherwise = m...

Counting unique elements in a list

Is there a straight-forward combination of standard higher-order funtions to count the unique elements in a list? For example the result for [1, 1, 4, 0, 4, 4] would be something like [(1,2), (4,3), (0,1)] ...

convert do notation to bind function

Hi I know that the following "do" notation's "bind" function is equivalent to getLine >>= \line -> putStrLn do line <- getLine putStrLn line But how is the following notation equivalent to bind function? do line1 <- getLine putStrLn "enter second line" line2 <- getLine return (line1,line2) ...

F# Type declaration possible ala Haskell?

I've looked a number of sources: it seems not possible to declare a type definition in F# ala Haskell: ' haskell type def: myFunc :: int -> int I'd like to use this type-def style in F#--FSI is happy to echo back to me: fsi> let myType x = x +1;; val myType : int -> int I'd like to be explicit about the type def signature in F# as...

How to go from String to Data.ByteString.Lazy in an existing Haskell code ?

Hi, I have a Haskell code which use a lot of String, while profilling it, it appear that the code use a lot of memory to store Lists []. One solution to this problem is to use Data.ByteString.Lazy instead of String, but what I have to care about while doing this ?, which part of the code have to be look carefully : fold, map, ... ? ...

How to restructurize a List in Haskell?

I have a list like this: (Pseudo notation) (X,...) -> (X,...) -> (X,...) -> ... | | | V V V (Y,...) (Y,...) (Y,...) | | | V V V (Z,...) (Z,...) (Z,...) Type is (Enum a, Bounded a) => [[(a,x)]]. But I need something like this: (X, ... -> .....