Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.haskell > #421
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.haskell |
| Subject | Re: choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a forever loop |
| Date | 2016-07-25 13:57 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87lh0pri2r.fsf@bsb.me.uk> (permalink) |
| References | <a59d2e31-b360-4365-911a-d28ccae7827a@googlegroups.com> |
meInvent bbird <jobmattcon@gmail.com> writes:
> choose 2,3,4,5 can run very fast,
> but when choose 6,7 it run into a forever loop
>
> theoretically, the number of items will be less in the list
>
> why it run forever?
>
> let input1 = replicateM 5 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
> let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted
> [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
> let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)],
> isSorted (input1!!i)]
> writeFile "logic3layer5.txt" $ unlines ascbefore
>
>
> for example, choose 5 can run very fast, but when reach 6, it run into
> a forever loop
>
> let input1 = replicateM 6 [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
> let {isSorted :: (Ord a) => [a] -> Bool; isSorted [] = True; isSorted
> [x] = True; isSorted (x:y:xs) = x > y && isSorted (y:xs)}
> let ascbefore = [show (input1!!i) | i <- [0..((length input1)-1)],
> isSorted (input1!!i)]
> writeFile "logic3layer6.txt" $ unlines ascbefore
That's very inefficient. [(input1!!i) | i <- [0..((length input1)-1)]]
is just a very complex and slow way to write input1. Try
unlines $ map show $ filter isSorted input1
--
Ben.
Back to comp.lang.haskell | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a forever loop meInvent bbird <jobmattcon@gmail.com> - 2016-07-25 01:39 -0700
Re: choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a forever loop meInvent bbird <jobmattcon@gmail.com> - 2016-07-25 01:48 -0700
Re: choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a forever loop meInvent bbird <jobmattcon@gmail.com> - 2016-07-25 01:58 -0700
Re: choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a forever loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-25 13:57 +0100
Re: choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a forever loop meInvent bbird <jobmattcon@gmail.com> - 2016-07-25 19:03 -0700
Re: choose 2,3,4,5 can run very fast, but when choose 6,7 it run into a forever loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-26 10:37 +0100
csiph-web