Skip to content

Instantly share code, notes, and snippets.

@yanok
Created May 15, 2018 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanok/2e33f01c696b7f86518eb0916ee3652b to your computer and use it in GitHub Desktop.
Save yanok/2e33f01c696b7f86518eb0916ee3652b to your computer and use it in GitHub Desktop.
-- InFor n -> for (g $ InFor f) $ \y -> for (runForFor (f $ ForFor $ \_ -> y) NotInFor) $ \x ->
-- _
data ForFor r t a where
For :: r (t a) -> (r a -> r (t b)) -> ForFor r t (t b)
Other :: r a -> ForFor r t a
unForFor :: Sqlam r t => ForFor r t a -> r a
unForFor (For m n) = for m n
unForFor (Other x) = x
instance Sqlam repr t => Sqlam (ForFor repr t) t where
for (For l m) n = For l $ \x -> for (m x) $ \y -> unForFor $ n $ Other y
for (Other m) n = For m $ \x -> unForFor $ n $ Other x
lam f = Other $ lam $ \x -> unForFor $ f $ Other x
f $$ x = Other $ (unForFor f) $$ (unForFor x)
table s = Other $ table s
yeild x = Other $ yeild $ unForFor x
newtype S a = S { runS :: [String] -> String }
instance Sqlam S [] where
for (S m) n = S $ \(v:vs) ->
"for (" ++ v ++ " <- " ++ m vs ++ ") " ++ runS (n $ S $ const v) vs
lam b = S $ \(v:vs) ->
"\\" ++ v ++ " -> " ++ runS (b $ S $ const v) vs
f $$ x = S $ \vs -> "(" ++ runS f vs ++ ") (" ++ runS x vs ++ ")"
table x = S $ \_ -> "table " ++ show x
yeild x = S $ \vs -> "yeild " ++ runS x vs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment