4 ms·
Just did a Haskell version of spark. It supports in 9 lines of code (exclude comment + empty line) Double instead of just Int. Negative numbers. https://github
by Mgccl 15y ago
Just did a Haskell version of spark.
It supports in 9 lines of code (exclude comment + empty line)
Double instead of just Int.
Negative numbers.
https://github.com/Mgccl/mgccl-haskell/blob/master/random/spark.hs https://github.com/Mgccl/mgccl-haskell/blob/master/random/sp...
- tome 15y agoI really like your version. Very neat!
- jcromartie 15y agoSame features. 4 SLoC of Ruby :) https://gist.github.com/1367091 https://gist.github.com/1367091
- silvestrov 15y ago'floor' on last line should be changed to 'round'. ▁▁▁▁▁▁▂▂▂▂▂▂▃▃▃▃▃▃▅▅▅▅▅▅▆▆▆▆▆▆▇ = floor ▁▁▁▂▂▂▂▂▂▃▃▃▃▃▃▅▅▅▅▅▅▆▆▆▆▆▆▇▇▇▇ = round
- jcromartie 15y agoThanks! Much better.
- jodrellblank 15y agoAnd here's a PowerShell version. (Use PowerShell ISE as PowerShell normal prompt doesn't support unicode). http://pastie.org/2867807 http://pastie.org/2867807 [edit: updated, careless variable rename, thanks jcromartie]
- jcromartie 15y ago$stats should be $minmax
- Mgccl 15y agoUpdated. thx to gwern. Now I know the existence of hlint. Now, without the type declaration, white space, comments, it's only 6 lines, and looks even better. :)
- ocharles 15y agoHere's a Haskell version that uses a single loop to do the normalizing, and has a main that doesn't use do syntax. This was mostly a nice little brainteaser: https://gist.github.com/1367709 https://gist.github.com/1367709 mapNormalize takes a function, and produces a function that runs that function with the normalized input. It runs in a single iteration, rather than 2 maps. Credit to `dylex` for much hand holding on a single iteration normalizer :)
- ddfisher 15y agoBecause Haskell is evaluated lazily, two maps doesn't imply two iterations over the data. In this case, I would expect only one pass through the data for both of the maps. Out of curiosity, I did a quick criterion benchmark for both functions. Here's the result on a list of 100 elements: benchmarking spark_mggcl mean: 49.29483 us, lb 48.77776 us, ub 50.25594 us, ci 0.950 std dev: 3.495423 us, lb 2.140951 us, ub 6.373469 us, ci 0.950 benchmarking spark_ocharles mean: 60.12347 us, lb 58.95586 us, ub 61.48084 us, ci 0.950 std dev: 6.434853 us, lb 5.529613 us, ub 7.824865 us, ci 0.950 The simpler version appears to be faster. (As an aside, is there something in particular you dislike about do syntax? I find that it often makes things more readable, though slightly more verbose.)
- ocharles 15y agoI am aware of that, as I said this was more a mental exercise. normalizeMap is harder to understand, but it was interesting to write - it wasn't meant to be a stab at your code or claim it's better :) In terms of do syntax, I try and avoid that because I find it detracts from the overall flow of data. With: "putStrLn . spark . map read =<< getArgs" I find it easy to see that main doesn't do much other than transform the users input. maybe a personal preference thing though...
- ranza 15y agoMy horrible php version :) https://gist.github.com/1368025 https://gist.github.com/1368025
- tanoku 15y agoI made my own Sparks in C. They look like Sparks. https://gist.github.com/1368661 https://gist.github.com/1368661