Skip to content

Instantly share code, notes, and snippets.

View iokasimov's full-sized avatar
🗿

Murat Kasimov iokasimov

🗿
View GitHub Profile
module Main where
import "concur-core" Concur.Core.Types (Widget (step), unsafeBlockingIO)
import "concur-core" Control.MultiAlternative (orr)
import "concur-replica" Concur.Replica (HTML, stepWidget)
import "concur-replica" Concur.Replica.DOM (button, ul, li, text, input, p)
import "concur-replica" Concur.Replica.DOM.Events (BaseEvent (target), targetValue, onClick, onInput)
import "concur-replica" Concur.Replica.DOM.Props (value)
import "focus" Focus (Focus, adjust)
import "lens" Control.Lens (_1, (%~))

Keybase proof

I hereby claim:

  • I am iokasimov on github.
  • I am iokasimovm (https://keybase.io/iokasimovm) on keybase.
  • I have a public key ASCLsUB6dGjFIPEsgHFtyMv8WxYz1R_kFFYlGDtJnsCTzAo

To claim this, I am signing this object:

{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LiberalTypeSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import Control.Joint.Core (type (:=))
import Control.Joint.Composition (run)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE LiberalTypeSynonyms #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
import Control.Applicative
import Control.Monad.Trans.Class
import Control.Monad.Trans.State.Lazy
import Data.Bool
import Data.Function
import Data.Peano
import Control.Monad
import Control.Comonad
import Control.Comonad.Cofree
@iokasimov
iokasimov / waterfall.hs
Created February 2, 2018 14:39
Elegant solution for waterfall problem based on time traveling.
import Control.Monad.Tardis
import Data.Traversable
water :: Traversable t => t Int -> Int
water = foldr (+) 0 . flip evalTardis (0, 0) . traverse (go 0) where
go :: Int -> Int -> Tardis Int Int Int
go total height = do
modifyForwards $ max height
(leftmax, rightmax) <- (,) <$> getPast <*> getFuture
@iokasimov
iokasimov / lens.hs
Last active January 10, 2018 15:06
Lenses are exactly the Coalgebras for the Store Comonad
import Data.Function
import Control.Comonad.Store
type Lens a b = a -> Store b a
(^.) :: Lens a b -> a -> b
(^.) lens = pos . lens
(.~) :: Lens a b -> b -> a -> a
lens .~ new = peek new . lens
import Data.Monoid
import Control.Concurrent
import qualified Control.Concurrent.Broadcast as Broadcast
biglog n = do
if n == 100000 then pure n
else print n >> biglog (n + 1)
main = do
data Vertice prior key = Vertice prior key deriving Show
data Treap p k = Nil | Branch (Treap p k) (Vertice p k) (Treap p k) deriving Show
-- simple in-order traversal
instance Foldable (Treap p) where
foldr f acc Nil = acc
foldr f acc (Branch left (Vertice p k) right) =
foldr f (f k $ foldr f acc right) left
insert :: (Ord k, Ord p) => Vertice p k -> Treap p k -> Treap p k
@iokasimov
iokasimov / trie.hs
Last active October 15, 2017 18:35
import Data.List
data Trie key value = Vertice value [Edge key value] deriving Show
data Edge key value = Edge key (Trie key value) deriving Show
example :: Trie Char Integer
example = Vertice 0 [
Edge 'h' $ Vertice 0 [
Edge 'e' $ Vertice 1 [],
Edge 'i' $ Vertice 0 [