News for hackers. Stuff that matters.
Re:C++ Pattern Matching Proposal [pdf] by lalaithion on Friday January 03, 2020 @12:26PM (#21948066)
Can you give an example of the pattern matching in ML and Erlang that is not idiomatic in Haskell?
Re:C++ Pattern Matching Proposal [pdf] by macintux on Friday January 03, 2020 @12:31PM (#21948125)
It's the multiple function heads which (again, I've been informed, no direct knowledge) is discouraged.

e.g. https://github.com/macintux/advent-of-code-2019/blob/master/...

Re:C++ Pattern Matching Proposal [pdf] by opus132 on Friday January 03, 2020 @12:56PM (#21948428)
You mean a piecewise definition of a function? I don't think this is unidiomatic or discouraged in Haskell at all.
Re:C++ Pattern Matching Proposal [pdf] by macintux on Friday January 03, 2020 @01:03PM (#21948512)
There's some indirect discussion here that seems to contradict that, but I certainly could be wrong.

https://github.com/elm/compiler/issues/973

Re:C++ Pattern Matching Proposal [pdf] by Iceland_jack on Friday January 03, 2020 @01:21PM (#21948714)
That's in the context of Elm, Evan gives his reasons but in the context of Haskell such multi-line equations are very common and normal Haskell style.
Re:C++ Pattern Matching Proposal [pdf] by a1369209993 on Friday January 03, 2020 @10:12PM (#21952597)
Translating that into Haskell, I get:

  check_each :: Int -> [Int] -> Bool -> Int -> (Bool,Bool,Int)
  check_each x (y:_) _ last | y==x && x==last = (True,False,x)
  check_each x (y:_) _ last | y>x && x==last = (True,True,x)
  check_each x (y:_) found _ | y>x = (True,found,x)
  check_each x _ found _ = (False,found,x)
  
  is_valid :: (Bool,Bool,Int) -> [Int] -> Bool
  is_valid (False,_,_) _ = False
  is_valid (True,True,-1) [_] = False
  is_valid (True,True,_) [_] = True
  is_valid (True,found,shortDup) (h:t) = is_valid (check_each h t found shortDup) t
which is ugly, certainly, but compiles fine (ghc). The uglyness mainly comes from the data structures, and I don't know enough about the domain to suggest better ones (there might not be better ones).
Re:C++ Pattern Matching Proposal [pdf] by macintux on Saturday January 04, 2020 @02:04PM (#21956674)
Well, it was code I threw together quickly for Advent of Code, so try not to be too hard on it.
Re:C++ Pattern Matching Proposal [pdf] by a1369209993 on Sunday January 05, 2020 @12:59AM (#21959939)
Eh, like I said, that might be the best you can do for a messy problem domain. I'm still not sure what you meant by multiple function heads though.