Found a deceptively simple solution.List comprehensions are great
1. Walking a directory in Haskell
With LambdaCase extension it is possible to write helper without do (but it does not seem much more readable):There is listDirectory function in recent directory package which can spare you a check for . and ...It is possible to create cyclic directory structure with symbolic links, so it may be reasonable not to traverse them. E.g. you can use getSymbolicLinkStatus from unix package to traverse only real directories:As lazy IO is considered deprecated, it is better to use iteratees/conduits/pipes to work with IO effectively and in compositional style. Here is an example using pipes:Check it with: runEffect $ walkDir "/" >-> stdoutLn
2. Is Haskell's type system formally equivalent to Java's? [closed]
One thing nobody's mentioned so far is type inference: a Haskell compiler can usually infer the type of expressions but you have to tell the Java compiler your types in detail. Strictly, this is a feature of the compiler but the design of the language and type system determines whether type inference is feasible. In particular, type inference interacts badly with Java's subtype polymorphism and ad hoc overloading. In contrast, the designers of Haskell try hard not to introduce features that impact type inference.Another thing people do not seem to have mentioned so far is algebraic data types. That is, the ability to construct types from sums ('or') and products ('and') of other types. Java classes do products (field a and field b, say) fine. But they do not really do sums (field a OR field b, say). Scala has to encode this as multiple case classes, which is not quite the same. And while it works for Scala it's a bit of a stretch to say Java has it. Haskell can also construct function types using the function constructor, ->. While Java's methods do have type signatures, you can not combine them. Java's type system does enable a type of modularity that Haskell has not got. It will be a while before there's an OSGi for Haskell
3. Lucky Triples in Haskell
I am not seeing the point of sort or mapFactors. The relationship between j and l is just the transitive relationship through k, so the total number of lucky triples is the sum over k of (number of j which work with this k) times (number of l which work with this k). Emphasis on number of: there's no need to generate an [Int] or to count them in any particular order.
4. Compile .tex and remove .div file from Haskell
When you are using packages, please make sure to say which ones. I guessed shellmate btw. As for the code, it's quite readable except for the handler definition which I've rewritten as follows:Given that you are quickly dismissing the cases you are not interested in, I inspected not $ isTeXFile f and systematically written the if (...) then clauses on the same line. This avoids the crazy right-leaning nesting. Using the either combinator of type (a -> c) -> (b -> c) -> Either a b -> c lets you rewrite the final case expression in a more concise fashion.Finally, I do not think it's good practice to test a file's type based on its extension. Given that you are already running external tools, you may want to use file for that job. It would look something like this:The rest is pretty much perfect as far as I am concerned (modulo some cosmetic preferences which I wo not bore you with)
5. Haskell function to format a floating-point number with some precision
I will hijack dirkt's solution and add my two cents.(Not quite sure plugging precision into padZeroes directly is right.)
6. What are some of the best time-saving tips for Haskell?
Get comfy in the REPL, write applications that can be cleanly stood up and torn down in the REPL end-to-end, work in the REPL.Learn to use undefined with assigned type signatures to pose hypothetical proofs in order to figure out if something is a dead end before bothering to write the actual code.Learn to use lens: Lenses, Folds and Traversals for manipulating data (products, sums, collections) in Haskell. Get comfortable with a streaming library such as Pipes, Conduit, or Machines so that when you need it, you wo not need to learn a streaming library at the same time as tackling the problem you are working on.What are some of the best time-saving tips for Haskell?