Sequence (toBlock $ VarDeclAssign "foo" (JBool False)) (Return $ JBool True)
This is the only way I can do it at the moment. I tried a foldl but EmptyBlock has a different type so it wouldn’t build.
Can I use do notation or something here instead?
Looking at the documentation, the problem is that the types of
EmptyBlockandSequenceareMost statements are of type
Stmt (), except forReturn :: Expr t -> Stmt t. From what I can tell, this is to ensure that there can only be a single return statement in a block, and it must be at the end.The reason why
foldl Sequence EmptyBlockdidn’t work for you is thatfoldlhas the type(a -> b -> a) -> a -> [b] -> a, and if you look at the first argument, it’s clear thatSequencecan only be used if you pickt = ()so thata = Block ()andb = Stmt ().This means that you can use
foldlto combine all statements except for theReturn, which you have to manually insert at the end. Hopefully, that shouldn’t be too inconvenient.