Better HN
topnewbestaskshowjobs
Log inSign up

hskl

0 karma · joined Dec 25, 2016 (9y ago) · 4 submissions

Submissions

comment 9y ago · link · parent

Here's your version translated to C#:

    xs.Aggregate("", (prev, cur) => { if (prev != "a" && cur != "a") parseLine(cur); return cur; });
Working demo: https://repl.it/EwaE

comment 9y ago · link · parent

That's why one should use more than a single one-line function per program.

comment 9y ago · link · parent

    > map parse . filter (not . startsWith "a")
Almost! You have to skip two lines.

comment 9y ago · link · parent

> for (int i =0;i<len;i++){ if(lines[i] == "a"){ i+=2; } else{ parseLine(lines[i]); } }

You must be one of those managers who like to dabble in coding! I don't even know what you wanted to do. Is that C++? That part `lines[i] == "a"` is string comparison, right? And `len` is the amount of lines, right? I'll use a list instead.

I'd do it in C# with LINQ but I'm at my folks, so I only have an iPad. Here's the biggest Haskell program I ever wrote in my entire career:

    dropTwoIf :: (Eq a) => a -> [a] -> [a]
    dropTwoIf _ [] = []
    dropTwoIf s (x:xs)
      | s == x    = dropTwoIf s (drop 1 xs)
      | otherwise = x : dropTwoIf s xs

    myList = [ "will pass", "will pass", "a", "will skip", "will pass", "a", "will skip", "a" ]
    main = mapM_ print (dropTwoIf "a" myList)
Result:

    "will pass"
    "will pass"
    "will pass"
Thanks for forcing me to actually do something bigger than Hello World of fib in this Haskell thing.

EDIT: Sure, it looks bigger than the for loop, but at least it has a name (but I'm not that good at naming) and it can be put in a library and reused. I'm pretty sure I could do MUCH better if I actually knew the standard library.

EDIT 2: Huh, figured out the type.