Skip to content

Instantly share code, notes, and snippets.

test = map ((*) 2) >>> filter ((>) 15) >>> drop 3 >>> map show
src1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
src2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
res1 = transduce' test src1 :: [String]
res2 = transduce' test src2 :: List String

DSl'и и как писать большие программы на PureScript'е

Вступление

Приветы! Меня зовут Максим Зималиев, я работаю в SlamData и уже почти два с половиной года пилю в продакшн код на PureScript'е. Как и большинство пришедших в прекрасный мир ФП, я начинал со всяких там джаваскриптов, пхп и шарпов. Соответственно, у меня есть бывшие коллеги и друзья, которые по-прежнему работают на императивных языках, используют GoF, DDD и тому подобное.

Ну так вот, пойдешь такой пиво пить, и внезапно "Слушай, а как у вас в PureScript'е, например ORM запилить, объектов же нет?" Или: "Это здорово всё, но вот я домены описываю вот так вот, у них там поведение есть, а как это PureScript'е сделать?"

-- | A “flushing” 'stream', with an additional coalgebra for flushing the
-- remaining values after the input has been consumed. This also allows us to
-- generalize the output away from lists.
fstream
:: (Cursive t (XNor a), Cursive u f, Corecursive u f, Traversable f)
=> Coalgebra f b -> (b -> a -> b) -> Coalgebra f b -> b -> t -> u
fstream ψ g ψ' = go
where
go c x =
let fb = ψ c
@xgrommx
xgrommx / streams.hs
Created January 19, 2018 05:18 — forked from michaelt/streams.hs
little streaming library
{-#LANGUAGE BangPatterns #-}
import GHC.Magic
import Data.IORef
import Control.Monad
import Control.Monad.Trans
data Stream a m r = Yield a (Stream a m r) | Done r | Delay (() -> m (Stream a m r))
instance Functor m => Functor (Stream a m) where
fmap f (Done r) = Done (f r)
@xgrommx
xgrommx / http.hs
Created October 30, 2017 22:10 — forked from markandrus/http.hs
Sketch for a testable, free monad-based HTTP client
{-#LANGUAGE DataKinds #-}
{-#LANGUAGE DeriveDataTypeable #-}
{-#LANGUAGE DeriveFoldable #-}
{-#LANGUAGE DeriveFunctor #-}
{-#LANGUAGE DeriveGeneric #-}
{-#LANGUAGE DeriveTraversable #-}
{-#LANGUAGE GADTs #-}
{-#LANGUAGE GeneralizedNewtypeDeriving #-}
{-#LANGUAGE KindSignatures #-}
{-#LANGUAGE TypeFamilies #-}
@xgrommx
xgrommx / frequency.hs
Created August 30, 2017 13:01 — forked from ybigus/frequency.hs
frequency
count:: Int -> [Int] -> Int
count x arr = length $ filter (\i -> i == x) arr
freq:: [Int] -> [Int] -> [(Int, Int)]
freq [] _ = []
freq (x:xs) acc = [(x, count x acc + 1)] ++ freq xs (x: acc)
example:: [(Int, Int)]
example = freq [1,2,1,2,4,2,1] []
@xgrommx
xgrommx / README.md
Created August 27, 2017 01:42 — forked from ujihisa/README.md

ISeq (Stack Machine)

data Inst = IPlus | IMult | ICall String | IPush Int |
  ILt | INeg | IZeroJump Int | IJump Int | ILabel Int |
  ISetLocal String | IGetLocal String deriving (Show, Eq)
  • IPlus
  • IMult
  • ILt
  • Consumes 2 values and stores the result of plus/mult/less-than by the two values

Stephen Diehl (@smdiehl )

Since I wrote these slides for a little user group talk I gave two years ago they have become a surprisingly popular reference. I decided to actually turn them into a proper skimmable reference for intermediate and advanced level Haskell topics that don't necessarily have great coverage or that tend be somewhat opaque as to where to get going, and then aggregate a bunch of the best external resources for diving into those subjects with more depth. Hopefully it still captures the "no bullshit brain dump" style that seemed to be liked.

The source for all code is available here. If there are any errors or you think of a more illustrative example feel free to submit a pull request.

@xgrommx
xgrommx / Either-hof.agda
Created April 14, 2017 00:42 — forked from madidier/Either-hof.agda
Sum type encoding and catamorphism of "Either" in various languages and approaches
-- I haven't been able to actually run the program (broken archlinux packages), but it typechecks
open import Data.String
open import Function
open import IO.Primitive
Either : Set → Set → Set₁
Either l r = {a : Set} → (l → a) → (r → a) → a
Left : { l r : Set } → l → Either l r
@xgrommx
xgrommx / Pascal.hs
Created April 11, 2017 07:15 — forked from queertypes/Pascal.hs
Pascal's triangle in Haskell
import Control.Applicative ((<$>))
center :: String -> Int -> String
center s n = spaces ++ s ++ spaces
where spaces = replicate ((n - length s) `div` 2) ' '
-- http://www.haskell.org/haskellwiki/Blow_your_mind, Ctrl-F "pascal"
pascal :: [[Int]]
pascal = iterate (\row -> zipWith (+) ([0] ++ row) (row ++ [0])) [1]