Please identify this programming language:
*Main> [ ((a,b,c),(d,e)) |
a <- [1..7],
b <- [2..8],
c <- [3..9],
d <- [1..8],
e <- [2..9],
a < b,
b < c,
d < e,
List.intersect [d,e] [a,b,c] == [],
a+b+c == 23,
d+e == 10 ]
output:
[((6,8,9),(3,7))]
I found the code in this blog comm...
This is my function signature:
foo :: Integer -> [String]
How this function should work:
foo 1234567 should return ["567", "234", "001"]
foo 12345678 should return ["678", "345", "012"]
foo 123456789 should return ["789", "456", "123"]
My current solution:
zeichenreihenBlock :: Integer -> [String]
zeichenreihenBlock x = reverse ...
I have the following code:
import operator
def stagger(l, w):
if len(l)>=w:
return [tuple(l[0:w])]+stagger(l[1:], w)
return []
def pleat(f, l, w=2):
return map(lambda p: f(*p), stagger(l, w))
if __name__=="__main__":
print pleat(operator.add, range(10))
print pleat(lambda x, y, z: x*y/z, range(3, 13), 3)
...
Hi,
I'm using ghc 6.12.2 and the latest Data.HashMap 1.1.0 package, and while compiling with options
+RTS -prof -auto-all
it does not work, and the message said that I didn't install the profiling package
How to install it ?
Thanks to reply
...
Can't figure out how to merge two lists in the following way in Haskell:
INPUT: [1,2,3,4,5] [11,12,13,14]
OUTPUT: [1,11,2,12,3,13,4,14,5]
This would work similar to shuffling a deck of cards.
Thanks in advance.
...
At first glance, there obvious distinctions between the two kinds of "class". However, I believe there are more similarities:
Both have different kinds of constructors.
Both define a group of operations that could be applied to a particular type of data, in other words, they both define an Interface.
I can see that "class" is much m...
During the last months I have tried to code using the functional programming paradigm. Now I have a solution in OOP and I am trying to find a functional solution.
The problem is simple. I have an algorithm, which produces two different arrays as result (a and b). Now, I want to check how good the results are. Therefore I write several ...
Haskell is a pure functional programming language.
My question is:
What are the advantages and disadvantages of using Haskell to solve problems involving lots of state, for example GUI programming or game programming?
Also a secondary question: what methods are there to handle state in a functional way?
Thanks in advance.
...
I have a polymorphic function like:
convert :: (Show a) => a -> String
convert = " [label=" ++ (show a) ++ "]"
But sometimes I want to pass it a Data.Map and do some more fancy key value conversion. I know I can't pattern match here because Data.Map is an abstract data type (according to this similar SO question), but I have been uns...
I want to make all types that are instances of Enum and Bounded also an instances of Random. The following code does this and should work (with the appropriate extensions enabled):
import System.Random
instance (Enum r, Bounded r) => Random r where
randomR (hi, lo) = inFst toEnum . randomR (fromEnum hi, fromEnum lo)
where inFs...
I'm writing a mini shell and although I've got most of it planned out, one thing I'm not sure how to do is implement piping the output of one program as the input of another. Is there a sample or something that can point me in the right direction?
...
I've looked at http://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl%27
and http://haskell.org/haskellwiki/Fold as well as a few others and they explain it fairly well.
I'm still having trouble on how a lambda would work in this case.
Example
foldr (\y ys -> ys ++ [y]) [] [1,2,3]
Could someone go through that step by step and try to e...
I can't figure out why m1 is apparently memoized while m2 is not in the following:
m1 = ((filter odd [1..]) !!)
m2 n = ((filter odd [1..]) !! n)
m1 10000000 takes about 1.5 seconds on the first call, and a fraction of that on subsequent calls (presumably it caches the list), whereas m2 10000000 always takes the same amount of...
For caching purposes, I want to create an array, which maps input values of the function to output values. I know, that my function will be used only in this specific range, I think about something like this:
MyType = ... deriving (Ix)
myFunction :: MyType -> foo
myCache = createArrayFromFunction (start,end) myFunction
Is this poss...
I have a haskell program that uses Data.Set and Data.IntMap, what flags do I need to give GHC to get it to link those libraries in? Simple question, I know, but the man pages didn't help me and I don't know where to look.
...
Hi,
I've been playing around with RankNTypes recently and wonder if it is possible to use them
in instance declarations.
Here is a simple example using open datatypes
data (Expr a, Expr b) => Add a b = Add a b deriving(Show)
instance (Expr a, Expr b) => Expr (Add a b)
instance (Evaluation a, Evaluation b) =...
I do:
Prelude> "sone" ++ "otehr"
"soneotehr"
But such code:
addOneToElement :: [a] -> [a]
addOneToElement element = element ++ "next"
main = do
let s = addOneToElement("some")
putStrLn s
produces this output:
all_possible_combinations.hs:22:37:
Couldn't match expected type `a' against inferred type `Char'
`a' is a...
How can exceptions be used in Haskell without going through IO?
I have the following code for inserting an element in a binary search tree with minimum comparisons and no copying when the element is a member of the tree. I noticed that either is used as catch and Left as throw:
insert x t = either (const t) id (insert' x t Nothing)
...
I'm writing Haskell, but this could be applied to any OO or functional language with a concept of ADT. I'll give the template in Haskell, ignoring the fact that the arithmetic operators are already taken:
class Thing a where
(+) :: a -> a -> a
(-) :: a -> a -> a
x - y = x + negate y
(*) :: (RealFrac b) => a -> b -> a
neg...
Title and tags should explain the question adequately.
...