Skip to content

Instantly share code, notes, and snippets.

View alogic0's full-sized avatar

Oleg Tsybulskyi alogic0

  • Odessa, Ukraine
View GitHub Profile
@alogic0
alogic0 / 2016-01-08-capriotti-vs-roman.md
Last active January 8, 2016 04:26
Free Applicative Functors and regex-applicative

http://www.paolocapriotti.com/assets/applicative.pdf

1.4 Example: applicative parsers The idea that monads are “too flexible” has also been explored, again in the context of parsing, by Swierstra and Duponcheel ([12]), who showed how to improve both performance and error-reporting capabilities of an embedded language for grammars by giving up some of the expressivity of monads. The basic principle is that, by weakening the monadic interface to that of an applicative functor (or, more precisely, an alternative

@alogic0
alogic0 / regex2parser.md
Created April 7, 2016 01:44
Tranlation of regex to parser combinator
/a/      => char 'a'
/abcd/   => string "abcd"
            sequence [ char 'a', char 'b', char 'c', char 'd' ]
            (:) <$> char 'a' <*> string "bcd"
            (++) <$> string "ab" <*> string "cd"

/[abcd]/ => oneOf "abcd"
/[^abcd]/ => noneOf "abcd"
/[a-z]/ =&gt; oneOf ['a'..'z']
@alogic0
alogic0 / tmp.md
Last active September 19, 2016 11:24
buffer for copy/paste

ghcjs-boot --dev --ghcjs-boot-dev-branch ghc-8.0 --shims-dev-branch ghc-8.0 step2 min (max 3 4) 5

src/Reflex/Dom/Internal.hs:224:28-37: error:
    * Expecting one more argument to `SpiderHost'
      Expected kind `* -> *', but `SpiderHost' has kind `* -> * -> *'
    * In the second argument of `HasPostGui', namely `SpiderHost'
      In the instance declaration for
 `HasPostGui Spider SpiderHost SpiderHost'
@alogic0
alogic0 / WiktionaryLookup.hs
Last active September 27, 2016 00:56 — forked from ali-abrar/WiktionaryLookup.hs
Text selection and iFrame with Reflex.Dom
-- source https://gist.github.com/ali-abrar/bca8f372b3ca39317f86/
{-# LANGUAGE JavaScriptFFI #-}
import Reflex.Dom
import qualified Data.Text as T
import Data.Monoid
import GHCJS.Types
import GHCJS.Foreign
import Control.Monad.IO.Class
import Control.Monad
@alogic0
alogic0 / bootstrap.hs
Last active September 27, 2016 00:57 — forked from ali-abrar/bootstrap.hs
Reflex.Dom and Bootstrap CSS
-- source https://gist.github.com/ali-abrar/080f8696c446c477b007
import Reflex.Dom
import Data.Monoid
main :: IO ()
main = mainWidgetWithHead headWidget bodyWidget
headWidget = do
elAttr "link" ("href" =: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" <> "rel" =: "stylesheet" <> "type" =: "text/css") $ return ()
@alogic0
alogic0 / somesquares.hs
Created September 27, 2016 00:58 — forked from ali-abrar/somesquares.hs
Simple Canvas Example
-- source https://gist.github.com/ali-abrar/47333e623b978d0472c2
{-# LANGUAGE ScopedTypeVariables #-}
import Reflex.Dom
import GHCJS.DOM.CanvasRenderingContext2D (putImageData, setFillStyle, fillRect)
import GHCJS.DOM.HTMLCanvasElement (getContext)
import GHCJS.DOM.ImageData (newImageData')
import Control.Monad.IO.Class (liftIO)
import GHCJS.DOM.Types (CanvasStyle(..), CanvasRenderingContext2D(..), toJSString, castToHTMLCanvasElement)
import GHCJS.Marshal (toJSVal)
import Data.Time (getCurrentTime)
@alogic0
alogic0 / typeahead.hs
Last active September 27, 2016 00:59 — forked from ali-abrar/typeahead.hs
June 4 2016 Reflex.Dom workshop (NY Haskell User's Group)
-- source https://gist.github.com/ali-abrar/2a52593f3a391d82c40f439d4894f017
{-# LANGUAGE ScopedTypeVariables, RankNTypes #-}
import Reflex.Dom
import Data.Monoid ((<>))
import Data.List (isPrefixOf)
main :: IO ()
main = mainWidgetWithHead headTag bodyTag
headTag :: MonadWidget t m => m ()
@alogic0
alogic0 / globalKeypress.hs
Created September 27, 2016 01:00 — forked from ali-abrar/globalKeypress.hs
Global keypress events
-- source https://gist.github.com/ali-abrar/6cdf28d6fb9c3dbe25fb
import Control.Monad.IO.Class
import GHCJS.DOM (webViewGetDomDocument)
import GHCJS.DOM.Document (getBody)
import GHCJS.DOM.Element (keyDown)
import GHCJS.DOM.EventM (on, preventDefault)
import Reflex.Dom
main :: IO ()
@alogic0
alogic0 / parseExpr.hs
Last active October 12, 2016 02:38
FutureLearn Haskell 2016, Parsing Text, Expression parsers
import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Expr
import qualified Text.ParserCombinators.Parsec.Token as P
import Text.ParserCombinators.Parsec.Language
import Control.Monad (liftM)
lexer = P.makeTokenParser emptyDef
parens = P.parens lexer
natural = P.natural lexer
@alogic0
alogic0 / primeS.hs
Created October 30, 2016 06:54
primes numbers, effective algorithm
-- source: http://www.garrisonjensen.com/2015/05/13/haskell-programs-are-lies.html
import qualified Data.Set as PQ
primes :: [Integer]
primes = 2:sieve [3,5..]
where
sieve (x:xs) = x : sieve' xs (insertprime x xs PQ.empty)
sieve' (x:xs) table