Skip to content

Instantly share code, notes, and snippets.

@MgaMPKAy
MgaMPKAy / Regex.hs
Created February 21, 2012 16:48
try to implement VBF.Compilers.Scanners.RegularExpression;
{-# LANGUAGE OverloadedStrings #-}
module Regex where
import GHC.Exts(IsString(..))
data Regex
= Empty
| Concatention Regex Regex
| Alternation Regex Regex
| KleeneStar Regex
@MgaMPKAy
MgaMPKAy / Arith.hs
Created February 22, 2012 04:34
Types and Programming Languages chapter 3
module Arith where
import Prelude hiding (True, False)
data Arith = Zero
| True
| False
| If Arith Arith Arith
| Succ Arith
| Pred Arith
@MgaMPKAy
MgaMPKAy / Recursive.hs
Created February 22, 2012 14:54
some simple recursive function
module Recursive where
g :: Int -> Int -> Int
g 0 _ = 0
g m n = g (m - 1) (2 * n) + n
f :: Int -> Int
f 0 = 1
f n = n * f (div n 2)
@MgaMPKAy
MgaMPKAy / Bisection.hs
Created March 6, 2012 07:44
bisection method
module Numeric.Bisection where
bisection f a b eps
| abs (a - b) < eps = mid
| f mid == 0 = mid
| f a * f mid < 0 = bisection f a mid eps
| otherwise = bisection f mid b eps
where mid = (a + b) / 2
module DJBX33A where
import Data.Char (ord)
djbx33a :: String -> Int
djbx33a str = foldl (\a c -> a * 33 + ord c) 5381 str
djbx :: Int -> Int -> String -> Int
djbx times init str = foldl (\a c -> a * times + ord c) init str
@MgaMPKAy
MgaMPKAy / gist:2122913
Created March 19, 2012 18:26
persistent example
{-# LANGUAGE QuasiQuotes, TypeFamilies, GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TemplateHaskell, OverloadedStrings, GADTs #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sqlite
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses, OverloadedStrings #-}
import Yesod
import Control.Applicative ((<$>), (<*>))
data SessionExample = SessionExample
mkYesod "SessionExample" [parseRoutes|
/ Root GET POST
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses, OverloadedStrings #-}
{-# LANGUAGE GADTs, FlexibleContexts #-}
import Yesod
import Database.Persist
import Database.Persist.Sqlite
import Database.Persist.TH
import Data.Time
@MgaMPKAy
MgaMPKAy / yesod and persisten
Created March 21, 2012 07:33
does not work well
{-# LANGUAGE TypeFamilies, QuasiQuotes, TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses, OverloadedStrings #-}
{-# LANGUAGE GADTs, FlexibleContexts #-}
import Yesod
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sqlite
import Control.Monad.IO.Class (liftIO)
import Control.Applicative ((<$>), (<*>))
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
{-# LANGUAGE TypeFamilies, GADTs, MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings, FlexibleContexts #-}
{-# LANGUAGE EmptyDataDecls #-}
import Database.Persist
import Database.Persist.TH
import Database.Persist.Sqlite
import Data.Text
import Control.Monad.IO.Class