Skip to content

Instantly share code, notes, and snippets.

returnFun :: Bool -> (Int -> Int)
returnFun = [egison| (lambda [$b] (if b (lambda [$x] (* x 2)) (lambda [$y] (* y 3)))) :: Bool -> (Int -> Int)|]
> returnFun True 9
18
> returnFun False 9
27
{-# Language TemplateHaskell, QuasiQuotes #-}
module ReifyTest where
import Language.Haskell.TH
import Language.Haskell.TH.Quote
import Data.Maybe
qq :: QuasiQuoter
qq = QuasiQuoter{quoteExp = \x -> litE . StringL .show =<< reify . fromJust =<< lookupValueName x}
add :: Int -> Int -> Int
add x y = [egison| (+ #{x} #{y}) :: Int|]
import Language.Egison.Quote
-- Antiquoting!
infixes :: [Int] -> [[Int]]
infixes l = [egison|(match-all l (List Integer) [<join _ <join $l _>> l]) :: [[Int]]|]
nqueen = [egison| (lambda [$n]
(match-all (between 1 n) (Multiset Integer)
[<cons $a_1
(loop $l $i (between 2 n)
<cons (loop $l1 $i1 (between 1 (- i 1))
(& ^,(- a_i1 (- i i1))
^,(+ a_i1 (- i i1))
l1)
$a_i)
l>
(define $take
(lambda [$n $l]
(match l (List Something)
{[(loop $l $i (between 1 n) <cons $a_i l> _) (loop $l $i (between 1 n) {a_i@l} {})]})))
> (define $f (lambda [$x $pat] (match-all x (Multiset Integer) [pat m])))
f
> (define $pat1 <cons $m <cons ,m _>>)
pat1
> (define $pat2 <cons $m <cons ,(- m 1) _>>)
pat2
> (define $x {2 3 3 4 5})
x
> (test (f x pat1))
{3}
-- GUILibrary.hs
-- アイコン画像を取得
getIcon :: String -> IO String
getIcon url = do
let outFile = "./icon/" ++ urlEncode url
fileExist <- doesFileExist outFile
if fileExist
then return outFile
else do
let request = defaultGETRequest $ fromJust $ parseURI url
-- GUILibrary.hs
-- アイコン画像を取得
getIcon :: String -> IO String
getIcon url = do
let outFile = "./icon/" ++ urlEncode url
fileExist <- doesFileExist outFile
if fileExist
then return outFile
else do
let request = defaultGETRequest $ fromJust $ parseURI url
{-# LANGUAGE TemplateHaskell, QuasiQuotes, NoMonomorphismRestriction #-}
module THUtility where
import Language.Haskell.TH
import Control.Monad
import Data.IORef
import Graphics.UI.Gtk hiding (add)
import Graphics.Rendering.Cairo
import Graphics.UI.Gtk.Gdk.GC
import Graphics.UI.Gtk.Glade
import Control.Applicative