forked from google/codeworld
-
Notifications
You must be signed in to change notification settings - Fork 1
Strange javascript(?) error message from non-termination #51
Copy link
Copy link
Open
Description
Some non-terminating computations cause errors in the what seems to be the generated javascript code.
uncaught exception in Haskell thread: RangeError: Invalid array lengthRangeError: Invalid array length
at h$p4 (https://codeworld.fmi.uni-due.de/runBaseJS?version=27657c86a58164ca9089ca52c1dd97c0a9a237e9bddfe423902bc284eb217031:8003:23)
at h$$fNi (<anonymous>:112:5)
at h$runThreadSlice (https://codeworld.fmi.uni-due.de/runBaseJS?version=27657c86a58164ca9089ca52c1dd97c0a9a237e9bddfe423902bc284eb217031:6560:11)
at h$runThreadSliceCatch (https://codeworld.fmi.uni-due.de/runBaseJS?version=27657c86a58164ca9089ca52c1dd97c0a9a237e9bddfe423902bc284eb217031:6532:12)
at h$mainLoop (https://codeworld.fmi.uni-due.de/runBaseJS?version=27657c86a58164ca9089ca52c1dd97c0a9a237e9bddfe423902bc284eb217031:6527:9)
at https://codeworld.fmi.uni-due.de/runBaseJS?version=27657c86a58164ca9089ca52c1dd97c0a9a237e9bddfe423902bc284eb217031:2145:25
at runIfPresent (https://codeworld.fmi.uni-due.de/runBaseJS?version=27657c86a58164ca9089ca52c1dd97c0a9a237e9bddfe423902bc284eb217031:2159:21)
at onGlobalMessage (https://codeworld.fmi.uni-due.de/runBaseJS?version=27657c86a58164ca9089ca52c1dd97c0a9a237e9bddfe423902bc284eb217031:2188:17)
Finding the problem (non-termination) from this error message is very difficult, especially since the message refers to array length.
The following program produces such an error.
divideAndConquer ::
(a -> Bool) ->
(a -> b) ->
(a -> (a, a)) ->
(b -> b -> b) ->
a ->
b
divideAndConquer simpleEnough simpleCases splitFunction combineFunction =
recursively
where
recursively input =
if simpleEnough input
then simpleCases input
else
let (left, right) = splitFunction input
in combineFunction (recursively left) (recursively right)
findSatisfying :: (Int -> Bool) -> Int -> Int -> Bool
findSatisfying p =
curry $
divideAndConquer
(\(x, y) -> x <= y)
(\(x, y) -> (x <= y) && (p x || p y))
(\(x, y) -> ((x, (x + y) `div` 2), (((x + y) `div` 2) + 1, y)))
(||)
main :: IO ()
main = print $ findSatisfying (const True) 0 (-1)(This problem also exists in the original codeworld instance.)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels