You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to PureScript and to learn it, I was implementing a solution to this problem: Project Euler 694. Guess what, when I tried to sort a list (Data.List.sort) of BigInts with about 80000 elements in it, the program crashed with stack out of memory error. So, I worked around it by converting the list to an array, sorting the array and converting the array back to a list.
Also, to wield my new found knowledge of PureScript, I implemented a merge-sort in purescript with a tail-recursive merge function. With this implementation of sort, the program ran successfully without any stack overflow errors. The code for the merge sort is available here: Merge Sort. Could someone replace the implementation of Data.List.sort with the above implementation so that we do not get any stack overflow errors for even modestly large size lists.
The text was updated successfully, but these errors were encountered:
Thanks for the report! Your implementation isn't quite suitable as it is right now: at the moment it only works on lists of BigInts, but we'd want it to have the type
forall a. Ord a => List a ->List a
It may also be worth doing some benchmarking to verify that this implementation is in fact faster than just converting to Array, using Array's sort, and converting back again.
Agreed. I know the merge-sort works only for BigInt's, I have not figured out generics for purescript yet, and do not know how to use generic compare functions. So, when I meant replace, I meant obviously to generify the above code and replace the Data.List.sort with it. The problem is not speed, the problem is the stack-out-of-memory error.
I am new to PureScript and to learn it, I was implementing a solution to this problem: Project Euler 694. Guess what, when I tried to sort a list (Data.List.sort) of BigInts with about 80000 elements in it, the program crashed with stack out of memory error. So, I worked around it by converting the list to an array, sorting the array and converting the array back to a list.
Also, to wield my new found knowledge of PureScript, I implemented a merge-sort in purescript with a tail-recursive merge function. With this implementation of sort, the program ran successfully without any stack overflow errors. The code for the merge sort is available here: Merge Sort. Could someone replace the implementation of Data.List.sort with the above implementation so that we do not get any stack overflow errors for even modestly large size lists.
The text was updated successfully, but these errors were encountered: