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
(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 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 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 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 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 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 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 Data.Array.IArray | |
sumA :: Array Int Int -> Int | |
sumA ary = foldl (\acc i -> acc + ary!i) 0 (indices ary) | |
main = do | |
let ary = listArray (1, 10) [1..] :: Array Int Int | |
print $ sumA ary |
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 Data.Array.IArray | |
import Data.Array.Unboxed | |
sumA :: Array Int Int -> Int | |
sumA ary = foldl (\acc i -> acc + ary!i) 0 (indices ary) | |
main = do | |
let ary = listArray (1, 10) [1..] :: Array Int Int | |
uary = listArray (1, 10) [1..] :: UArray Int Int | |
print $ sumA ary |
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 GADTs, KindSignatures, DataKinds, TypeOperators, TypeFamilies #-} | |
data Nat = Zero | Succ Nat | |
data SNat (n :: Nat) where | |
SZero :: SNat 'Zero | |
SSucc :: SNat m -> SNat ('Succ m) | |
type family NIntArrow (a :: Nat) | |
type instance NIntArrow 'Zero = Int | |
type instance NIntArrow ('Succ n) = Int -> NIntArrow n |
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 GADTs, KindSignatures, DataKinds, TypeOperators, TypeFamilies #-} | |
data Nat = Zero | Succ Nat | |
data SNat (n :: Nat) where | |
SZero :: SNat 'Zero | |
SSucc :: SNat m -> SNat ('Succ m) | |
type family NIntArrow (a :: Nat) | |
type instance NIntArrow 'Zero = Int | |
type instance NIntArrow ('Succ n) = Int -> NIntArrow n |