I have just started learning functional programming and Haskell and am I not even close to understanding the syntax and how it works because it is very different from what I have been used to before (ruby, php, C# or node for instance, which are OOP languages - more or less).
I am am trying to put together a small program that checks for solutions for Brocard's Problem or so called Brown Numbers and I first created a draft in ruby, but I discovered that Haskell is much more appropriate for doing mathematical expressions. I've asked a question previously and I got an answer pretty quick on how to translate my ruby code to Haskell:
results :: [(Integer, Integer)] --Use instead of `Int` to fix overflow issue
results = [(x,y) | x <- [1..1000], y <- [1..1000] , 1 + fac x == y*y]
where fac n = product [1..n]
I changed that slightly so I can run the same operation from and up to whatever number I want, because the above will do it from 1 up to 1000 or any hardcoded number but I would like to be able to decide the interval it should go through, ergo:
pairs :: (Integer, Integer) -> [(Integer, Integer)]
pairs (lower, upper) = [(m, n) | m <- [lower..upper], n <- [lower..upper], 1 + factorial n == m*m] where factorial n = product [1..n]
The reason I ask this questions is that I was thinking if I could run this operations in parallel (and/or on multiple threads and/or cores) and append the results to the same variable.
I have not yet understood the parallel processing in Haskell or the threading model, but in ruby a good example of how the threading model works is something like this:
def func1
i=0
while i<=2
puts "func1 at: #{Time.now}"
sleep(2)
i=i+1
end
end
def func2
j=0
while j<=2
puts "func2 at: #{Time.now}"
sleep(1)
j=j+1
end
end
puts "Started At #{Time.now}"
t1=Thread.new{func1()}
t2=Thread.new{func2()}
t1.join
t2.join
puts "End at #{Time.now}"
And in my case, the func1 and func2 would be the same function results computed on different intervals ([1..1000] -> [i..j]).
I would appreciate some help with this as I am not capable of doing it myself at this point :)