Is it possible to declare assignment operators in Haskell?

Hello! 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 http://eax.me/

On 2/5/2014 7:37 AM, Alexander Alexeev wrote:
Hello!
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.
There are things that "act like assignment", but quite differently than what you are after, which looks like a macro of some sort. For instance, one of the OpenGL packages defines (:=) = writeIORef, to be used like spoofel depth stencil = do stencilVals <- map (> 0.35) <$> readIORef depth stencil := stencilVals What is the type of (.=) and (:=) that you desire? What is the larger problem you are trying to solve?

Hi Alexander, 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.
Adam
On Wed, Feb 5, 2014 at 7:37 AM, Alexander Alexeev
Hello!
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 http://eax.me/ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
adam vogt
-
Alexander Alexeev
-
Joe Quinn