I am looking at this example using getOpts, and one portion of it really baffles me: the syntax of field labels.
First, this seems simple enough, creating a data type and declaring the initial values:
data Options = Options { optVerbose :: Bool
, optInput :: IO String
, optOutput...
I have an optimization problem I want to solve. You have some kind of data-structure:
data Foo =
{ fooA :: Int
, fooB :: Int
, fooC :: Int
, fooD :: Int
, fooE :: Int
}
and a rating function:
rateFoo :: myFoo -> Int
I have to optimize the result of rateFoo by changing the values in the struct. In this specific case, I dec...
I'm trying to learn Haskell by writing little programs... so I'm currently writing a lexer/parser for simple expressions. (Yes I could use Alex/Happy... but I want to learn the core language first).
My parser is essentially a set of recursive functions that build a Tree. In the case of syntax errors, I'd normally throw an exception (i.e...
This is entirely theoretical at this point, but I've been trying to wrap my
head around this problem. Let's take a client for an example. There are
forkIOd threads for every connection, and one of them wants to quit the
entire program (ie. /exit). How would this information be propagated to
other threads?
This is not a condition, but ...
I'm used to debug my code using ghci. Often, something like this happens (not so obvious, of course):
ghci> let f@(_:x) = 0:1:zipWith(+)f x
ghci> length f
Then, nothing happens for some time, and if I don't react fast enough, ghci has eaten maybe 2 GB of RAM, causing my system to freeze. If it's too late, the only way to solve this pr...
Take a quick peek at the following interactive session in GHCi:
Prelude> import Control.Applicative
Prelude Control.Applicative> (+1) <$> [1,2]
[2,3]
Prelude Control.Applicative> (+1) <$> (1,2)
(1,3)
I guess there is a good reason for the behavior of <$> regarding pairs, but I wasn't able to find one so far, so:
why is <$> (or `fma...
Hi all,
Im pretty new to Haskell.
I have a datatype:
data Sentence= Prop Int
| No Sentence
| And [Sentence]
| Or [Sentence]
deriving Eq
I already wrote a Show instance for it
However, whether it makes sense or not, I would like to be able to generate a random Sentence.
How can i accomplish this...
iterate :: (a -> a) -> a -> [a]
(As you probably know) iterate is a function that takes a function and starting value. Then it applies the function to the starting value, then it applies the same function to the last result, and so on.
Prelude> take 5 $ iterate (^2) 2
[2,4,16,256,65536]
Prelude>
The result is an infinite list. (th...
As my first programming language, I decided to learn Haskell. I'm an analytic philosophy major, and Haskell allowed me to quickly and correctly create programs of interest, for instance, transducers for natural language parsing, theorem provers, and interpreters. Although I've only been programming for two and a half months, I found Hask...
I am trying to name what I think is a new idea for a higher-order function. To the important part, here is the code in Python and Haskell to demonstrate the concept, which will be explained afterward.
Python:
>>> def pleat(f, l):
return map(lambda t: f(*t), zip(l, l[1:]))
>>> pleat(operator.add, [0, 1, 2, 3])
[1, 3, 5]
Haskell...
Still a Haskell newbie here. I know just enough to get myself into trouble with wrong assumptions. If I have the following function...
quadsum w x y z = w+x+y+z
I want a function that can take a list, use each element as a parameter in a specified function like quadsum, and return a curried function for later use.
I've been trying ...
I need a data-structure, which supports the following operations both memory and time-efficient, it can be assumed, that the value has an ordering.
Add a value to the structure
Find out, whether a value is in the structure
Plus, the structure has to be immutable, because I want to use Haskell.
If I would not assume immutability, pro...
What does a very general function look like in functional programming?
Somebody said "we don't have objects, but we have higher order functions". Do higher order functions replace objects?
While programming object-oriented apps, I try to go from a more general to a more detailed idea, lots of times. If I try to do that in functional pr...
Hi all,
I'm looking to learn functional programming with either Haskell or F#.
Are there any programming habits (good or bad) that could form as a result Haskell's lazy evaluation? I like the idea of Haskell's functional programming purity for the purposes of understanding functional programming. I'm just a bit worried about two things...
I have two functions:
lowerString :: [Char] -> [Char]
lowerString = filter (/='_')
upperString :: [Char] -> [Char]
upperString [] = []
upperString (x:xs)
| x == '_' = x : upperString (tail xs)
| otherwise = ' ' : upperString(xs)
If I apply them on "_A_B_CDEF":
upperString "_A_B_CDEF" would return ___
lowerString "_A_B_CDEF...
Haskell's Network.Browser module seems to not do any compression. How can I configure it so that it does gzip compression assuming that the server supports it (or fall back to no compression if it doesn't) ?
...
Reading Disadvantages of Scala type system versus Haskell?, I have to ask: what is it, specifically, that makes Haskell's type system more powerful than other languages' type systems (C, C++, Java). Apparently, even Scala can't perform some of the same powers as Haskell's type system. What is it, specifically, that makes Haskell's type s...
First, I understand the how of iteratees, well enough that I could probably write a simplistic and buggy implementation without referring back to any existing ones.
What I'd really like to know is why people seem to find them so fascinating, or under what circumstances their benefits justify their complexity. Comparing them to lazy I/O...
Is there an elegant notation for Currying the arguments of a function out of order in Haskell?
For example, if you wish to divide 2 by all elements of a list, you can write
map ((/) 2) [1,2,3,4,5]
However to divide all elements of a list it seems you need to define an anonymous function
map (\x -> x/2) [1,2,3,4,5]
Anonymous functi...
Hi
I have to solve a following problem.
there are many files let's say 3 for example, with the following content
file1
a1
a2
a3
a4
a5
a6
......
file2
b1
b2
b3
b4
b5
b6
......
file3
c1
c2
c3
c4
c5
c6
......
my program has to take filenames in parameter, read those files and print the following result
"a1 b1 c1"...