Created
February 22, 2014 00:24
-
-
Save gavinwahl/9146571 to your computer and use it in GitHub Desktop.
Statically typed stack language. http://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html
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 RankNTypes #-} | |
(!) = flip (.) | |
lit :: a -> s -> (s, a) | |
lit x s = (s, x) | |
run :: (forall a. a -> (a, b)) -> b | |
run x = snd $ x undefined | |
lift1 :: (a -> b) -> (s, a) -> (s, b) | |
lift1 f = \(s, a) -> (s, f a) | |
lift2 :: (a -> b -> c) -> ((s, a), b) -> (s, c) | |
lift2 f = \((s, a), b) -> (s, f a b) | |
plus :: Num a => ((s, a), a) -> (s, a) | |
-- plus ((s, a), b) = (s, a + b) | |
plus = lift2 (+) | |
ap1 :: ((s, a), a -> b) -> (s, b) | |
ap1 ((s, a), f) = (s, f a) | |
ap2 :: (((s, a), b), a -> b -> c) -> (s, c) | |
ap2 (((s, a), b), f) = (s, f a b) | |
dup :: (s, a) -> ((s, a), a) | |
dup (s, a) = ((s, a), a) | |
swap :: ((s, a), b) -> ((s, b), a) | |
swap ((s, a), b) = ((s, b), a) | |
drop' :: (s, a) -> s | |
drop' = fst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment