Skip to content

Instantly share code, notes, and snippets.

@andrevdm
andrevdm / registry02.hs
Created March 12, 2021 14:51
Registry with one effect using another
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
module Lib
( run
) where
import Protolude
@andrevdm
andrevdm / registry01.hs
Last active March 12, 2021 14:49
Basic registry example
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
module Lib
( run
) where
import Protolude
@andrevdm
andrevdm / ReaderT constraint with record.hs
Created October 1, 2017 19:38
Has* class constraint with record in ReaderT
#!/usr/bin/env stack
{- stack
script
--resolver lts-9.3
--package text
--package protolude
--package text
-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
@andrevdm
andrevdm / ConcurReplica.hs
Last active July 17, 2020 08:14
Concur-Replica with static middleware and CSS
import Protolude
import qualified Concur.Core as CC
import qualified Concur.Replica as CR
import qualified Data.Map.Strict as Map
import qualified Data.Text as Txt
import qualified Network.Wai.Handler.Replica as WR
import qualified Network.Wai.Handler.Warp as Wa
import Network.Wai.Middleware.Static ((>->))
import qualified Network.Wai.Middleware.Static as MwS
import qualified Network.WebSockets.Connection as Wsc
@andrevdm
andrevdm / Main.hs
Last active June 22, 2020 14:39
Haskell perlin noise terrain (2D ascii) with SDL2 display
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
module Main (main) where
import Protolude
import Foreign.C.Types (CInt (..))
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeApplications #-}
@andrevdm
andrevdm / SimpleWebsockets.hs
Last active December 23, 2019 11:47
Haskell websockets - standalone
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
import Protolude hiding (finally)
import Control.Exception.Safe (finally)
import qualified Network.WebSockets as Ws
main :: IO ()
main = do
@andrevdm
andrevdm / polysemyIntercept.hs
Created November 11, 2019 13:59
Polysemy intercept e.g
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
@andrevdm
andrevdm / ValidationEff.hs
Last active August 26, 2019 08:14
Demo Validation effect for polysemy
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
@andrevdm
andrevdm / ValidationDef.hs
Last active August 26, 2019 06:03
Validation Monad, with default value on validation fail
-- Validation monad that requires a defaul value on validation failure
-- This allows the code to run as far as possible and accumulate more
-- validation errors.
-- Also since there is always a valid value (the original or the default)
-- it means that we can make <*> = ap unlike the usual validation monads
-- | Validation
-- +---- Type to accumulate errors in e.g. []
-- |
-- | +------ Invalid type, i.e. type of error to accumulate