This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- cabal: | |
default-language: GHC2021 | |
build-depends: base ^>= 4.17 | |
, array | |
ghc-options: -threaded | |
-rtsopts | |
-with-rtsopts=-N | |
-} | |
{-# LANGUAGE CPP, Strict, UnliftedDatatypes, StandaloneKindSignatures, MagicHash, UnliftedNewtypes #-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.List.NonEmpty as NE | |
import Data.List (sortOn, sort) | |
import qualified Data.Set as Set | |
import Data.Function | |
uniqueFactorsAndSums :: Set.Set (Int, Int) | |
uniqueFactorsAndSums = | |
[(x * y, x + y) | x <- [1..1000], y <- [x..1000]] | |
& NE.groupAllWith fst | |
& filter ((== 1) . length) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FailedParse : Exception {} | |
class Parser | |
{ | |
string text; | |
int state; | |
private Parser(string text) | |
{ | |
this.text = text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE NoMonoLocalBinds, NoMonomorphismRestriction #-} | |
{-# LANGUAGE FlexibleContexts, TypeApplications #-} | |
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} | |
{-# LANGUAGE Strict, DataKinds, LambdaCase #-} | |
{-# LANGUAGE TupleSections #-} | |
import Data.Word | |
import Data.Bits | |
import Data.Maybe | |
import Control.Effects.State | |
import Data.IntSet (IntSet) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DataKinds, KindSignatures, GADTs, TypeOperators, TypeFamilies, PolyKinds, ConstraintKinds #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
module RestrictConstructors where | |
import Data.Word | |
import Data.Int | |
data Mode = | |
ImpliedMode | |
| AccumulatorMode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE Rank2Types, MultiParamTypeClasses, FlexibleInstances #-} | |
{-# LANGUAGE FlexibleContexts, TypeApplications, RecordWildCards #-} | |
{-# LANGUAGE UndecidableInstances, TypeFamilies, ExistentialQuantification #-} | |
{-# LANGUAGE ScopedTypeVariables, LambdaCase #-} | |
{-# OPTIONS_GHC -Wall #-} | |
module Continuations where | |
import Control.Monad.Trans | |
import Control.Monad.Base | |
import Control.Monad.Trans.Control | |
import Control.Monad.State.Lazy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type family Elem (x :: k) (xs :: [k]) :: Bool where | |
Elem x '[] = 'False | |
Elem x (x ': xs) = 'True | |
Elem x (y ': xs) = Elem x xs | |
type family If (condition :: Bool) (t :: k) (e :: k) :: k where | |
If 'True t e = t | |
If 'False t e = e | |
type family Without (xs :: [k]) (ys :: [k]) :: [k] where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pure_array* write_arr(int idx, elem x, pure_array* arr, | |
void (*io_write)(int, elem, io_vector), | |
io_vector (*io_clone)(io_vector), | |
elem (*io_read)(int, io_vector)) | |
{ | |
elem old_val; | |
pure_array* new_arr = (pure_array*)malloc(sizeof(pure_array)); | |
switch (arr->rep.tag) | |
{ | |
case 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveFunctor, DeriveFoldable #-} | |
import Data.Monoid | |
import Data.Foldable | |
import Control.Monad | |
type Point = (Int, Int) | |
type Patch = (Point, Point) | |
data Quad a = Quad a a a a deriving (Eq, Ord, Read, Show, Functor, Foldable) | |
data FillStatus = Empty | Partial | Full deriving (Eq, Ord, Read, Show) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE ViewPatterns #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module BoolLike where | |
import Prelude hiding ((&&), (||), not) | |
import qualified Prelude as P |
NewerOlder