I searched the web for different solutions to the n-queens problem in Haskell but couldn't find any that could check for unsafe positions in O(1) time, like that one that you keep an array for the / diagonals and one for the \ diagonals.
Most solutions I found just checked each new queen against all the previous ones. Something like thi...
I use mostly R and C for statistics-related tasks. Recently
I have been dealing with large datasets, typically 1e7-1e8
observations, and 100 features. They seem too big for R too
handle, and the package I typically use are also more prone
to crashing. I could develop tools directly in C or C++, but
this would slow down the development cy...
I am working on Project Euler question 4, and need to find the palindrome of the product of 2 3 digit numbers, so I came up with:
palindrome = [ x*y | x <- [100..999], y <- [100..999], reverse [x*y] == [x*y]]
Why doesn't this work and how can I make it work?
I suspect I need to somehow get the answer into a list so that it be reverse...
I've been curious to understand if it is possible to apply the power of Haskell to embedded realtime world, and in googling have found the Atom package. I'd assume that in the complex case the code might have all the classical C bugs - crashes, memory corruptions, etc, which would then need to be traced to the original Haskell code that
...
I am trying to walk through the functions in Data.List of the Haskell stardard library and get an error when trying "permutations". What am I missing here? Thanks.
Prelude> map (\b-> b*b) [1,2,3]
[1,4,9]
Prelude> permutations "abc"
<interactive>:1:0: Not in scope: `permutations'
...
Hi,
I want to write the code that will output :
length [1,2,3] => 3
In Ruby, I could do it like :
puts "length [1,2,3] => #{[1,2,3].length}"
Following try is Haskell failed...
Prelude Data.List> print "length [1,2,3]"
"length [1,2,3]"
Prelude Data.List> print (length [1,2,3])
3
Prelude Data.List> print "length [...
I would like to how can we implement producer/consumer in a functional programming language like Haskell? and how it will be different from an Imperative language? My understanding of functional programming language is primitive. Any help will be appreciated.
...
Hi ,
I met a problem caused by the tricky Indentation, here is the code looks in VI :
1 import Data.List
2 myQuickSort [] = []
3 myQuickSort (x:xs) = myQuickSort smaller ++ [x] ++ myQuickSort bigger
4 where smaller = filter ( < x ) xs
5 bigger = filter ( >=x ) xs
But after ./cat 3.hs , It looks ,
root@...
Hi
I am doing another project euler question and I need to find when the result of these 3 lists is equal (we are given 40755 as the first time they are equal, I need to find the next:
hexag n = [ n*(2*n-1) | n <- [40755..]]
penta n = [ n*(3*n-1)/2 | n <- [40755..]]
trian n = [ n*(n+1)/2 | n <- [40755..]]
I tried adding in the o...
Is it possible to use something similar to where-clauses in Scala? Maybe there is some trick I didn't think of?
Edit:
Thanks for all your answers, they are very much appreciated. To sum up:
Local vars, vals and defs can be used to achieve almost the same thing. For lazy evaluation, one can use lazy val (with implicit caching) or functi...
Hi!
I'm new to this.
How do I store a TreeStore to a file? I can store specific values from the underlaying TreeStore through the TreeModel interface, but is there any way of "grabbing" the whole underlaying TreeStore as a value, or do I have to traverse the TreeStore, storing a row at a time?
/J
...
Hi,
What is the haskell way to do this?
for (int i = 0 ; i < 1000 ; i++)
for (int j = 0 ; j < 1000 ; j++)
ret = foo(i , j ) #I need the return value.
More background:
I am solving euler problem 27 , and I have got:
value a b =
let l = length $ takeWhile (isPrime) $ map (\n->n^2 + a * n + b) [0...
Hi!
Running the following program will print "space overflow: current size 8388608 bytes." I have read this and this, but still don't know how to resolve my problem. I am using foldr, shouldn't it be guaranteed to be "tail recursive"?
I feel great about Haskell so far until I know I should prevent "space overflow" when using the powe...
Hi.
A person on Reddit has brought this code to my attention:
main = do
let ns = [print 1, print 2, print 3]
sequence_ ns
sequence_ $ reverse ns
sequence_ $ tail ns ++ [head ns]
head ns
What's going on here is we have an array of operations that we can do stuff with, like reverse or get its tail or head.
Awesome.
What I w...
I compiled and installed haddock-2.4.2 from the tarball source.
Adding a few simple comments to the code here:
https://dl.getdropbox.com/u/143480/doc/DualMap.hs
and running haddock
$ haddock -h -o doc Data/DualMap.hs
Warning: Data.DualMap: could not find link destinations for:
Data.Typeable.Typeable2 GHC.Base.Eq GHC.Show.Show G...
I am teaching myself Haskell
I want to write a function that recursively finds the first number that has an integer square root and is smaller than a starting number.
It looks like this:
findFirstSquare :: Int -> Int
findFirstSquare x
| x <= 0 = error "This function only works for 1 or above"
| fr...
I'm going a little nuts trying to figure out how to use template inheritance in Haskell's HStringTemplate. Basic template usage is easy enough, but missing something inheritance is concerned. Can anyone point me in the direction a decent example? The document below just isn't complete enough to graduate to more advanced usage.
http://ww...
Hi!
I have a TreeStore with objects that I view and manipulate through a GTK TreeView/TreeModel setup.
I also have a TreeView showing a treeModelSort of the treeStore, which I use for sorting on columns like name and date.
The problem is, that the sort mechanism only sorts the rootnodes, even if a underlaying childnode has e.g. a date...
So, I'm just starting to teach myself Haskell out of the book Real World Haskell, and in the course of doing one of the exercises, I wrote the following code:
step acc ch | isDigit ch = if res < acc
then error "asInt_fold: \
\result overflowed"
...
I'm trying to figure out the behavior of the library function groupBy (from Data.List), which purports to group elements of a list by an "equality test" function passed in as the first argument. The type signature suggests that the equality test just needs to have type
(a -> a -> Bool)
However, when I use (<) as the "equality test" i...