This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Expression { | |
int evaluate(); | |
} | |
public class Constant implements Expression { | |
private final int value; | |
Constant(int value) { this.value = value; } | |
public int evaluate() { return value; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void test() { | |
Environment env = new Environment(); | |
env.register(assign($("a"), plus($("b"), $("c")))); | |
env.register(assign($("c"), multiply($(2), $("d")))); | |
env.register(assign($("b"), $(3))); | |
env.register(assign($("d"), $(2))); | |
Assert.assertThat(env.valueOf($("a")), equalTo(7)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The responsibility for controlling a child's access to the Internet should lie with the parents, not with a central Government authority. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
digraph G { | |
KRC -> Miranda; | |
ML -> Miranda; | |
KRC -> SASL; | |
SASL -> Miranda; | |
Miranda -> Haskell; | |
Hope -> Haskell; | |
ML -> Caml; | |
Caml -> FSharp; | |
Clean -> Haskell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-} | |
module Handler.Root where | |
import FortuneSearch | |
import Search | |
import Data.Text (Text) | |
import qualified Data.Text as T | |
import Yesod.Json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Search ( | |
getKeyValues | |
, parseQuery | |
, query | |
) where | |
import FortuneIndexer (getTerm) | |
import qualified Data.Text as T | |
import Database.Redis.Redis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module FortuneIndexer ( | |
getTerm | |
) where | |
import Control.Monad (forM_) | |
import Data.List.Split (splitOn) | |
import Data.Char (isLetter, isSpace) | |
import Data.Text.Encoding as E |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.Text.IO as T | |
import Data.List.Split (splitOn) | |
splitOnPercent :: T.Text -> [T.Text] | |
splitOnPercent = T.splitOn "%" | |
splitOnBlankLines :: T.Text -> [T.Text] | |
splitOnBlankLines t = (init . map T.concat) (splitOn [" "] (T.lines t)) | |
fortunes :: [(FilePath,T.Text -> [T.Text])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.Text as T | |
import Text.ParserCombinators.Parsec | |
import Text.ParserCombinators.Parsec.Combinator | |
import Text.ParserCombinators.Parsec.Char | |
import Text.ParserCombinators.Parsec.Expr | |
import Text.ParserCombinators.Parsec.Token | |
import Text.ParserCombinators.Parsec.Language | |
import Text.ParserCombinators.Parsec.Error | |
data Query = Contains T.Text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compareLists :: [String] -> [String] -> Int -> [(String,String)] | |
compareLists x y dist = nearest | |
where | |
-- Hashes | |
hashX = map (computeHash . FV) x | |
hashY = map (computeHash . FV) y | |
-- Lookups | |
nameX = zip hashX x | |
nameY = zip hashY y | |
nearest = [(fromJust $ lookup hx nameX |