Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. I'm completely new to Haskell and I've been using in Advent of Code. I'm loving everything about the languages except regex.
  2.  
  3. Why do we need like 10 different (yet the same) libraries for regex? It's fair if the wiki mentions "hey look there are other regex libraries you may want to use", but instead it talk about them all in detail. All I care about when I google "haskell regex" is examples of how to use regex in Haskell: finding all matching strings, whether there is a match or not, etc. All the basic stuff you'd expect with regex.
  4.  
  5. Afterwards I managed to find an example for "Text.Regex.Posix". I do know what POSIX is, but I'm afraid I have no idea what's the difference between the different regexes is. Well, I found out this one barely supports anything you'd expect in a modern regex library: even \d is not supported. I know, I know, that's a limitation of POSIX regex, but I'm using Haskell, and I expect the built-in library to support all (what's considered nowadays) basic regex features.
  6.  
  7. So somehow I managed to make it work. Only issue is, for some reason I needed to use a pragma "OverridableStrings". Why does a simple feature like regex requires language changing pragmas?
  8.  
  9. My next problem actually extracting the matches. I don't know if this is usual, but it seems there's literally one regex operator =~ and then you need to cast its result to something. Bool to say if there is a match? Sure, makes sense. Get all matches? (String, String, String, [String]) and ignore 3 first parameters. Jesus Christ. Why not simply have a findAllMatches regex str which returns a [String]?
  10.  
  11. The I noticed in the wiki that I shouldn't be using this Text.Regex.Posix since it's mega slow and shouldn't be used for anything (why is it built-in then)... So I tried the suggested regex-tdfa. Ok, great, so how do I use it? Where are the examples? I tried using the same function but importing TDFA instead but it threw a bunch of errors at me so I abandoned that. Completely.
  12.  
  13. Finally I tried the super fast super amazing PCRE Heavy. Worked fine on macOS. Windows? Literally impossible. Tried everything Google suggested, nothing worked.
  14.  
  15. Forgive me for the rage, but I find it hard to believe a basic feature like regex is so hard in Haskell. Literally every other language I tried (php, js, java, python, ruby, go, scala) has superb support for regex. Why not Haskell? What am I doing wrong? Am I missing something, is there a better alternative?
  16.  
  17. This is not a troll post, I genuinely want to understand better.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement