Skip to content

Instantly share code, notes, and snippets.

View paolino's full-sized avatar

Paolo Veronelli paolino

  • Cardano Foundation
  • albufeira, portugal
View GitHub Profile
@paolino
paolino / countdown.hs
Created November 5, 2022 13:07
Countdown game with pruning
{-# LANGUAGE MultiWayIf #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
{-# HLINT ignore "Redundant multi-way if" #-}
module Counting () where
-- some values
type S a = [a]
@paolino
paolino / counting.hs
Last active November 12, 2022 18:56
Counting problem, unpruned
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
module Counting () where
-- some values
type S a = [a]
-- any combining operation between 2 values (+, - , * ...)
type Op a = a -> a -> a
@paolino
paolino / lev.hs
Last active November 2, 2022 11:06
fixpoint + dynamic programming implementation of levenshtein distance
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE TupleSections #-}
{-# HLINT ignore "Redundant multi-way if" #-}
import Control.Monad.Fix (fix)
import Data.Array (Array, array)
import qualified Data.Array as A
levCachedArray :: Eq a => [a] -> [a] -> Int
@paolino
paolino / BorsFailure.md
Last active July 26, 2022 17:27
Bors Failures Lifecycle
sequenceDiagram
    participant Bors
    participant Hydra
    participant User   
    participant GitHub 
    participant BorsComment
    participant Analyzer
    participant Automation
    participant Slack   
@paolino
paolino / TrackFilter.hs
Last active March 14, 2022 21:58
track a streaming filter activity
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
import Control.Monad.Fix (fix)
import Data.List (tails)
import Streaming (Of ((:>)), Stream)
import qualified Streaming.Prelude as S
@paolino
paolino / UncurryShwartz.hs
Last active March 12, 2022 17:52
Parameterize the cartesian sorting
{-# LANGUAGE BlockArguments #-}
module CartesianProductEx where
import Control.Arrow ((***))
import Data.List (sortOn)
import Test.Hspec (shouldBe)
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ViewPatterns, TemplateHaskell #-}
module Data.Tracer where
import Data.Functor.Contravariant
import Data.Time (getCurrentTime)
import Control.Lens
@paolino
paolino / atto.hs
Last active September 13, 2020 15:46
extract an enclosed subtext with attoparsec
import Control.Applicative ((<|>))
import Data.Attoparsec.Text hiding (match)
import Data.Text (Text)
atto :: Text -> Text -> Text -> Either String [Char]
atto x y = parseOnly $ untilWord x >> untilWord y
untilWord :: Text -> Parser [Char]
untilWord x = mempty <$ string x <|> (:) <$> anyChar <*> untilWord
@paolino
paolino / extract.hs
Last active September 13, 2020 14:59
extract an enclosed sublist
extract :: Eq a => [a] -> [a] -> [a] -> Maybe [a]
extract start end xs = do
ys <- snd <$> split start xs
fst <$> split end ys
split :: Eq a => [a] -> [a] -> Maybe ([a], [a])
split p = go id
where
go _ [] = Nothing
@paolino
paolino / divModIso.hs
Last active September 1, 2020 06:20
optics for things like div mods
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Lens -- (over)