This file contains hidden or 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
| 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 |
This file contains hidden or 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 #-} | |
| 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} |
This file contains hidden or 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
| add :: Int -> Int -> Int | |
| add x y = [egison| (+ #{x} #{y}) :: Int|] |
This file contains hidden or 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 Language.Egison.Quote | |
| -- Antiquoting! | |
| infixes :: [Int] -> [[Int]] | |
| infixes l = [egison|(match-all l (List Integer) [<join _ <join $l _>> l]) :: [[Int]]|] |
This file contains hidden or 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
| 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> |
This file contains hidden or 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
| (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} {})]}))) |
This file contains hidden or 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
| > (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} |
This file contains hidden or 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
| -- 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 |
This file contains hidden or 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
| -- 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 |
This file contains hidden or 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, 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 |