
I'm currently reading a C++ tutorial. (Don't ask!) Of course, C++ is that crazy language where *assignment* is actually an *operator*. Sick, sick people... The tutorial pointed out that "x = 4" is a legal assignment, but "4 = x" is not. "Obviously that would be silly." Now it occurs to me... in Haskell, "4 = x" is actually a perfectly legal thing to say. (!) It's pretty pointless, but it's legal. For example: foo x = let 4 = x in 2*x which, as best as I can tell, does exactly the same thing as (2*). In a similar vein, one might write foo x = do let 4 = x return (2*x) which also does more or less the same as (return). However, consider the following: foo :: Int -> Maybe Int foo x = do 4 <- return x return (2*x) This, it turns out, is an extremely odd way of checking whether x == 4. All of this works of course because in Haskell, "=" is not an assignment, it's a definition, and the RHS is not a variable, it's a pattern. And "4" is a perfectly legitimate pattern. Now, if only I could find a use for all this that borders on "useful"...! ;-)

All of this works of course because in Haskell, "=" is not an assignment, it's a definition, and the RHS is not a variable, it's a pattern. And "4" is a perfectly legitimate pattern. Now, if only I could find a use for all this that borders on "useful"...! ;-)
I like this one: let {1 + 1 = 3; 3 + 1 = 3} in 1 + 1 + 1 Right answer, for the wrong reasons. Useful? Well... does confusing people count as useful?

2008/9/18 Evan Laforge
All of this works of course because in Haskell, "=" is not an assignment, it's a definition, and the RHS is not a variable, it's a pattern. And "4" is a perfectly legitimate pattern. Now, if only I could find a use for all this that borders on "useful"...! ;-)
I like this one:
let {1 + 1 = 3; 3 + 1 = 3} in 1 + 1 + 1
Right answer, for the wrong reasons. Useful? Well... does confusing people count as useful?
Well, Andrew says it himself : it's practical because you can pattern match against specific value : f [] = ... f (4:xs) = ... f (x:xs) = ... Thu

Hello,
More fun for all of us to enjoy:
http://www.haskell.org/haskellwiki/Obfuscation
__
Donnie
On Thu, Sep 18, 2008 at 11:01 PM, Steven Shaw
2008/9/19 Evan Laforge
let {1 + 1 = 3; 3 + 1 = 3} in 1 + 1 + 1
Which gives 3.
Perhaps even more confusing is:
let {1 + 1 = 3; 3 + 1 = 3} in 3 + 1 + 1
which gives 3 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I think it's because + is left associative. and pattern matching is
top to bottom.
1 + 1 + 1 => (1 + 1) + 1 => found match: 1 + 1 = 3 => 3 + 1 => found
match: 3 + 1 = 3 => 3
On Thu, Sep 18, 2008 at 11:01 PM, Steven Shaw
2008/9/19 Evan Laforge
let {1 + 1 = 3; 3 + 1 = 3} in 1 + 1 + 1
Which gives 3.
Perhaps even more confusing is:
let {1 + 1 = 3; 3 + 1 = 3} in 3 + 1 + 1
which gives 3 _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, Sep 18, 2008 at 11:59 AM, Andrew Coppin
foo :: Int -> Maybe Int foo x = do 4 <- return x return (2*x)
Now, if only I could find a use for all this that borders on "useful"...! ;-)
It seems a lot less weird when you write something like: [x | (x,0) <- map (`divMod` n) [1..20]] which picks out 1/nth of each of the elements of [1..20] that are divisible by n. -- Dan

On Thu, 18 Sep 2008 19:59:51 +0100, you wrote:
Of course, C++ is that crazy language where *assignment* is actually an *operator*. Sick, sick people...
That's really not all that strange. An (infix) operator is just a function with funny syntax, and assignment is a function (the identity function, in fact) that also has a side effect. Steve Schafer Fenestra Technologies Corp. http://www.fenestra.com/
participants (8)
-
Andrew Coppin
-
Dan Piponi
-
Donnie Jones
-
Evan Laforge
-
minh thu
-
sam lee
-
Steve Schafer
-
Steven Shaw