4 ms·
I know what enum is, but data for me is just 1 and 0. Are we assigning here with the =? What does the pipe symbol mean? Why pipe instead of another =? Why the
by tiborsaas 7y ago
I know what enum is, but data for me is just 1 and 0.
Are we assigning here with the =? What does the pipe symbol mean? Why pipe instead of another =? Why the weird formatting?
To me Haskell's look is too off-putting. With the Rust example I have a good guess what will the resulting object will look like.
But I know it's just a learning experience. Once I would know Haskell your example looks more elegant to me. I just don't get it from looking at it :)
- thethirdone 7y agoYour questions are probably mostly rhetorical, but I'll give a brief answer to them. > Are we assigning here with the =? Kindof you are assigning what the type `Tree a` is. > What does the pipe symbol mean? The pipe is symbolizing or/either here. A tree is either a Leaf or it is a Node with two subtrees. > Why pipe instead of another =? You are building up a single type with the pipes, having an extra = wouldn't really make sense when you are thinking about building a type algebraically. > Why the weird formatting? The formatting is optional. It is free to be all in one line if you want it that way. For the given example, I would probably make it a single line, but I'm not a Haskell veteran.
- globuous 7y agoHence Eich’s famous « I was under marketing orders to make it look like Java » :)
- tiborsaas 7y agoWell, the marketing folks were right after all :)
- mrkeen 7y agoHaskell: A Tree ="IS" a Leaf |"OR" a Node In the Rust syntax ',' means both OR and AND. A Tree {"IS" a Leaf ,"OR" a Node A Node ("IS" an A ,"AND" a Box ,"AND" a Box.
- the_af 7y agoThe formatting is no weirder than Python's. You could ask many of the same questions of Python's non-C/non-Java like syntax: - What is "def"? - Why the weird formatting? (And unlike Haskell, Python's tends to be stricter!) - Why do I need to write ":" after some lines but not others? It doesn't work like the semicolon in C-like languages! - What's with the "if __name__ == '__main__'" weirdness I see in some Python programs? - What's this weird [f(x) for x in ...] syntax? It doesn't look like anything in C. What's with the brackets anyway? Etc. Yet Python with its "weird" syntax and constructs is a hugely popular language...
- tiborsaas 7y agoI tend to agree, but python is much easier to google: https://www.google.com/search?q=haskell+pipe+operator&oq=haskell+pipe+operator https://www.google.com/search?q=haskell+pipe+operator&oq=has... https://www.google.com/search?q=__name__+%3D%3D+%27__main__&oq=__name__+%3D%3D+%27__main__ https://www.google.com/search?q=__name__+%3D%3D+%27__main__&...
- the_af 7y agoPython is more popular than Haskell, which is why it's easier to google. Do note Haskell tutorials and communities abound, and you have excellent online tools such as Hoogle (in which you write the type of what you think you want and it responds with "these are functions with a similar type signature, with their documentation"). It's easy to google Haskell things, just not as easy as googling Python things :) Do note the type definitions from the example are Haskell 101 and will be covered very early in almost every tutorial, for example Learn you a Haskell. PS: it's not a "pipe operator" you're looking for. This isn't an operator at all! The "|" you're looking for it's in a definition, and it means a union of alternatives (this type can be "this" or "that" or "this other thing"). If you think about it, this "union-or" is written the same as the bitwise-or from more popular languages :)