Can some one explain what the !a does in this: data Color3<http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-VertexSpec.html#t%3AColor3>a = Color3<http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-VertexSpec.html#v%3AColor3>!a !a !a http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL... Thanks, Daryoush
Daryoush Mehrtash wrote:
Can some one explain what the !a does in this:
data Color3 <http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-VertexSpec.html#t%3AColor3> a = Color3 <http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL-GL-VertexSpec.html#v%3AColor3> !a !a !a
http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL...
In short, http://haskell.org/onlinereport/decls.html#strictness-flags -- Dr. Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:voigt@tcs.inf.tu-dresden.de
A simple example to help understand the difference
data NoStrict a = NoStrict a deriving Show data Strict a = Strict !a deriving Show
ns1 = NoStrict () ns2 = NoStrict undefined ns3 = undefined
nf1 (NoStrict ()) = "ok" nf2 (NoStrict _) = "ok"
s1 = Strict () s2 = Strict undefined s3 = undefined
f1 (Strict ()) = "ok" f2 (Strict _) = "ok"
The difference between these: *Strict> nf2 ns2 "ok" *Strict> f2 s2 "*** Exception: Prelude.undefined s2 and s3 are both the same (undefined), while ns2 and ns3 are different. As to why you'd want that behavior? Here are a couple of reasons: 1) You can avoid hiding exceptions in strict data structures; if the top level evaluates, you know the entire structure is valid. 2) With -funbox-strict-fields, the compiler can remove a level of indirection; the performance difference between a structure that contains three machine words and a structure that contains three pointers to boxed integers is pretty significant. On the other hand, you lose the benefits of laziness; I find most "structure-like" data structures work better strict, but that "list-like" data structures definitely gain an advantage from laziness. -- ryan 2008/7/8 Daryoush Mehrtash <dmehrtash@gmail.com>:
Can some one explain what the !a does in this:
data Color3 a = Color3 !a !a !a
http://cvs.haskell.org/Hugs/pages/libraries/OpenGL/Graphics-Rendering-OpenGL...
Thanks,
Daryoush
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Daryoush Mehrtash wrote:
Can some one explain what the !a does in this:
data Color3 a = Color3 !a !a !a
Shameless plug: http://www.vex.net/~trebla/haskell/strict-field.xhtml
participants (4)
-
Albert Y. C. Lai -
Daryoush Mehrtash -
Janis Voigtlaender -
Ryan Ingram