The original code (~7.2s on my laptop).
import System.Random
import System.CPUTime
rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
// Implementations for: | |
// Select | |
// - { Enumerable, AsyncEnumerable } * { Action, Func, Func<_,Task>, Func<_,Task<T>> } | |
// = 8 | |
// - Enumerable/Action and Enumerable/Func (bad? and already defined) | |
// = 6 | |
// + 2 CancellationToken versions | |
// = 8 |
The original code (~7.2s on my laptop).
import System.Random
import System.CPUTime
rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
{-# LANGUAGE RankNTypes, PolyKinds, TupleSections, TypeFamilies, TypeFamilyDependencies #-} | |
import Data.Kind (Type) | |
type LensFamily (outer :: t -> Type) (inner :: t -> Type) = | |
forall a b f. Functor f => (inner a -> f (inner b)) -> (outer a -> f (outer b)) | |
type family Snd b a = r | r -> b a where Snd b a = (a, b) | |
type family Fst a b = r | r -> a b where Fst a b = (a, b) | |
type family Id t = r | r -> t where Id x = x |
struct Six : Nat { public int Value => 6; } | |
void Main() | |
{ | |
var four = new Mod<Six>(4); | |
var two = new Mod<Six>(2); | |
Console.WriteLine(four + two == 0); | |
} |
#include <Windows.h> | |
#include <functional> | |
#include <memory> | |
#include <system_error> | |
void CALLBACK InvokeFunction(PTP_CALLBACK_INSTANCE, void* context, PTP_WORK) | |
{ | |
std::unique_ptr<std::function<void()>> owned{ static_cast<std::function<void()>*>(context) }; | |
(*owned)(); |
using System; | |
using System.Collections.Concurrent; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ExampleLoop | |
{ | |
class Program | |
{ | |
const int maxQueuedItems = 10; |
void Main() | |
{ | |
var digits = Digits.Create("093884765"); | |
var digitsOfLength3 = Digits3.Create("007"); | |
Console.WriteLine($"digits: [{digits}] digitsOfLength3: [{digitsOfLength3}]"); | |
} | |
static class DigitsDef | |
{ |
async Task Main() | |
{ | |
var c = new AsyncCache<int, int>(async x => { await Task.Delay(x); return x; }); | |
var s = Stopwatch.StartNew(); | |
var x1 = Enumerable.Range(1, 1000); | |
var results = | |
await Task.WhenAll(x1.Select(async x => | |
await Task.WhenAll( | |
// hit it in parallel |
void Main() | |
{ | |
Tree<int> m = (((1, 2), (3, 4)), (5, (6, 7))); | |
Console.WriteLine(m.Sum()); | |
} | |
abstract class Tree<T> : IEnumerable<T> | |
{ | |
class Leaf : Tree<T> | |
{ |