Skip to content

Instantly share code, notes, and snippets.

@paluh
paluh / ConstructorName.purs
Last active December 3, 2017 20:29
Constructor name serializer
module Main where
import Prelude
import Data.Generic.Rep
import Type.Prelude (class IsSymbol, Proxy, reflectSymbol, SProxy(..))
import Control.Monad.Eff (Eff)
import Data.Foldable (fold)
module VSemigroupoid where
data V err a = Valid a | Invalid err
data Vfun err a b = Vfun (a -> V err b)
instance semigroupoidV :: Semigroupoid (Vfun err) where
compose (Vfun f2) (Vfun f1) = (Vfun \a -> case f1 a of
Valid b -> f2 b
Invalid err -> Invalid err)
class SemigroupJoinRecord rl (row ∷ # Type) where
appendRecordsImpl :: RLProxy rl → Record row -> Record row -> Record row
instance semigroupJoinRecordCons ∷ (Semigroup ty, RowCons name ty row' row, SemigroupJoinRecord tail row, IsSymbol name) ⇒ SemigroupJoinRecord (Cons name ty tail) row where
appendRecordsImpl _ r1 r2 =
let
_name = (SProxy ∷ SProxy name)
v1 = get _name r1
const http = require('http');
const port = 3000;
const getString = (length) => {
var s = "a";
while(s.length * 2 < length) s = s + s;
s += s[length - s.length];
return s;
};
module Main where
import Prelude
import Control.IxMonad ((:*>))
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Data.String (take)
import Debug.Trace (traceAnyA)
import Hyper.Node.Server (defaultOptionsWithLogging, runServer)
@paluh
paluh / MonoidalRecords.purs
Created March 20, 2018 15:19
Some utils to work with "monoidal records"
module Utils.Record where
import Data.Monoid (class Semigroup, (<>))
import Data.Record (get, modify)
import Type.Prelude (class IsSymbol, class RowToList, RLProxy(RLProxy), SProxy(SProxy))
import Type.Row (Cons, Nil)
class AppendSubrecordImpl rl bigger smaller where
appendSubrecordImpl :: RLProxy rl -> Record bigger -> Record smaller -> Record bigger
@paluh
paluh / Extra.purs
Created March 20, 2018 20:57
`newtype Record' r = Record' (Record r)` which provides `Monoid` and `Eq`
module Data.Record.Extra.Extra where
import Prelude
import Data.Monoid (class Monoid, mempty)
import Data.Newtype (class Newtype, unwrap, wrap)
import Data.Record (get, insert, modify)
import Type.Prelude (class IsSymbol, class RowLacks, class RowToList, SProxy(SProxy))
import Type.Row (kind RowList, Nil, Cons, RLProxy(..))
@paluh
paluh / WrapRecord.purs
Created March 24, 2018 21:34
Wrap/unwrap fields of a record
module Wrap where
-- | Wrap fields (possibly sublist) into newtype
class WrapFields rl row f row' | row f → row' where
wrapFieldsImpl ∷ RLProxy rl → (∀ a. a → f a) → Record row → Record row'
instance wrapFieldsCons ∷
( IsSymbol name
, RowCons name t without row
@paluh
paluh / Main.purs
Last active April 20, 2018 20:34
Fun with Functional Dependencies in Purescript
module Main where
data Proxy a = Proxy
data Zero
data Su n
type Three = Su (Su (Su Zero))
class Even n where
@paluh
paluh / Main.purs
Last active April 20, 2018 21:19
Overlapping instances in type level computation
module Main where
import Prelude
import Data.Foldable (fold)
import TryPureScript (p, render, text)
-- | Till 0.12 release we don't have instance chains and we have to deal with overlapping instances ourselfs.
-- | To define order of type class resolution we have to name instances in alphabetical order.