Skip to content

Instantly share code, notes, and snippets.

View paolino's full-sized avatar

Paolo Veronelli paolino

  • Cardano Foundation
  • sesimbra, portugal
View GitHub Profile
@paolino
paolino / Parser.hs
Last active November 11, 2023 19:32
Arithmetic expression parser
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
module Arith where
-- do not import other stuff here
import Control.Applicative
( Alternative (empty, (<|>))
, many
@paolino
paolino / optparse.hs
Created September 13, 2023 15:49
A famous applicative
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.String (IsString)
@paolino
paolino / changeBrute.hs
Last active November 13, 2022 19:11
counting coins, brute force
module Change () where
import Data.List (sortOn)
import Data.Ord (Down(..))
import Control.Exception.Base (assert)
-- count the number of ways a `tot` can be realized using the given coins
-- any coin can be used any number of times
countChangeOpen :: Int -> [Int] -> Int
countChangeOpen tot coins = consumeOpen tot $ sortOn Down coins
@paolino
paolino / ranking.hs
Created November 12, 2022 18:33
kata track from codewars
module CodewarRanking (incProgress, newUser, rank, progress) where
import Data.Foldable (find)
-- just for differentiate the 2 Ints in the game
-- deriving Enum and Num would improve the code, how ?
newtype Progress = Progress Int
deriving (Eq, Show)
-- just for differentiate the 2 Ints in the game
@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)