[Haskell-cafe] I really don't understand this
jm at alliot.org
Tue Jan 23 13:35:04 UTC 2018
I apologize if my question is stupid, but here is a simple Haskell
program which never stops.
However, if I comment the line (which is apparently useless):
The program works like a charm...
I am using GHC 8.0.2 (debian sid) and multiset 0.3.3. If anyone has an
idea, I would gladly hear it.
Thanks in advance
PS: don't try to understand what the program is doing; it is just the
reduction to a few lines of a much larger code; I have tried to find a
smaller subset which is not working "properly".
PPS: The program can also be downloaded from:
import qualified Data.IntMultiSet as IMS
b :: IMS.IntMultiSet
b = IMS.fromList ([1, 2, 3, 4])
search :: IMS.IntMultiSet -> Int -> IO Bool
search mynumbers nb = ins mynumbers (return False)
ins numbers acc = do
v <- acc
(\x acc1 ->
let numbers2 = IMS.delete x numbers
(\y acc2 ->
let numbers3 = IMS.delete y numbers2
res = x + y
in if res == nb
then (return True)
else ins (IMS.insert res numbers3) acc2)
main = do
v <- search b 999999999
More information about the Haskell-Cafe