[Haskell-cafe] Is it possible to declare assignment operators in Haskell?
vogt.adam at gmail.com
Wed Feb 5 22:01:30 UTC 2014
You could quote the whole do-block:
> $(strictify [| do y .= x; ... |])
And then strictify :: ExpQ -> ExpQ manipulates the AST a bit: x .= y does
parse as an expression, so you can change a NoBindS containing that .=
function into a BindS or LetS. Unfortunately the quotes built into TH
complain about undefined variables, so you'll probably have to use a
quasiquote instead (haskell-src-meta can help here).
Also, you may want to desugar to "let !x = y `deepseq` y", or involve
(return $!) since "let x = y `deepseq` y where y = undefined :: Int" only
crashes when you seq the x.
On Wed, Feb 5, 2014 at 7:37 AM, Alexander Alexeev <mail at eax.me> wrote:
> I'm wondering, is there any way to declare assignment operators
> in Haskell? For example, strict assignment operators:
> x .= y -- equals: let x = y `deepseq` y
> x := y -- equals: x <- y `deepseq` y
> As far as I can tell, Template Haskell is not able to do anything like
> this, because I can't event quote expressions like `let x = y` or `x <-
> y`. Is there any other way (plugin for GHC, etc)? Or maybe I'm doing
> something wrong and TH is quite able to handle this task?
> I'm pretty sure that I could use a preprocessor, but I wonted to find
> a better solution.
> Best regards,
> Alexander Alexeev
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe