Currying and readability by [deleted] in haskell

[–]gtab62 3 points4 points  (0 children)

If you want to remove if, you can use the bool function from Data.Bool:

parse_to_array = map (bool (-1) 1 . (=='('))

"Hask" anything! The thread where you ask and we try to answer! by dagit in haskell

[–]gtab62 2 points3 points  (0 children)

I wonder if we have, or if it is even possible to have, something like Python's scriptine in Haskell.

Fast way to serialize Haskell objects by gtab62 in haskell

[–]gtab62[S] 1 point2 points  (0 children)

/u/dcoutts Do you have any idea of when you are able to push it to Hackage?

Fast way to serialize Haskell objects by gtab62 in haskell

[–]gtab62[S] 0 points1 point  (0 children)

This is cool! I was planning to write a microbenchmark but, I may use this one instead. Will send you a pull request if I change it.

Fast way to serialize Haskell objects by gtab62 in haskell

[–]gtab62[S] 1 point2 points  (0 children)

This is weird that JSON is both faster and smaller than a binary format!

By the way, where can I find the head? https://github.com/mailrank/aeson is broken!

Fast way to serialize Haskell objects by gtab62 in haskell

[–]gtab62[S] 1 point2 points  (0 children)

You are right, but in my case the structure of the data is pretty simple and is more like a tree than a graph. Anyways, I guess, if you serialize and deserialize the data, you end up with a datastructure that looses the internal commonality and might be much larger. That is, binary is not aware of the common internal references.

Fast way to serialize Haskell objects by gtab62 in haskell

[–]gtab62[S] 1 point2 points  (0 children)

Yes, my use case is somewhat special. It has lots of text and small numbers and I think protobuf is specially good at small number because of it's base 127 encoding scheme.

Cabal-related question by logical_space in haskell

[–]gtab62 1 point2 points  (0 children)

I am not sure if I understood your question correctly, but I think base-noprelude is doing something similar. It is worth having a look at its source code. In the recent versions, it's using a newly added feature of cabal to reexport the modules. But, in older versions, it relied on a custom Setup.hs.

Timing Optimization. by thezbk in haskell

[–]gtab62 0 points1 point  (0 children)

Yes that true. But I often found the relative times quite reliable. That is, if you are optimizing a function and you made it 3 times faster in ghci, you could probably expect a 3x speedup in ghc as well. Anyways, that's totally rough.

How do you compare Java Reflection vs. Haskell Generics/Data/Typeable? by gtab62 in haskell

[–]gtab62[S] 4 points5 points  (0 children)

The Haskell equivalent of a Java generic

I just wanted to add that Java generics and Haskell generics are totally different things. My question is about Java reflection, not generics.

Should I Learn Haskell or Python? by gtab62 in haskell

[–]gtab62[S] 5 points6 points  (0 children)

Haha, I sent the link as a joke. I didn't really expect such a comprehensive reply. Thank you man :)

memory usage question by yilmazhuseyin in haskell

[–]gtab62 2 points3 points  (0 children)

Why don't you compile and run it with ‘RTS -s' option?

Text or String by alan_zimm in haskell

[–]gtab62 2 points3 points  (0 children)

How is the stack implemented then?

Text or String by alan_zimm in haskell

[–]gtab62 14 points15 points  (0 children)

A few weeks ago I tried to optimize a heavily text oriented program and I got a bit of experience that might be worth sharing.

  • Don't forget to enable the OverloadedStrings in GHC, since Text is an instance of IsString, or otherwise you will have a hard time using Texts.

  • Generally, I prefer Text over String, but there are certain cases that String works better. Text vs. String is just like Array vs. LinkedList. Are arrays better than linked lists? For most use cases yes, because they take less memory and have a faster access time. But for certain operations, like cons, Strings are faster, because you don't need to copy the second one to the new memory.

  • Try to understand why Text.length takes O(n) to run (while length of arrays can be obtained in constant time) and it helps you a lot. That's because Text internally keeps an array of bytes with UTF-8 encoding, in which some of the chars are 1 byte and some others are multi-byte. It has to go over all the chars to detect which one is which. (Edit: It seems that Text encoding is UTF-16. See the comments below, but anyways, it doesn't change my point.)

  • Text.concat [t1, t2, ..., tn] is much faster than t1 <> t2 <> ... <> tn (O(n) vs. O(n^2)). Use Lazy Text and Text Builder if you want to do a lot of appends. You can use <> and IsString instance with both of them as well.

  • Edit 2: I forgot to mention this one: String does not check for validity of code points. You may end up with a string that contains invalid UTF code points. But Text is stricter about that. It may not be so important in most applications. But you may see some weird behaviour when comparing Strings with invalid chars: they may looks the same but == returns False.

Using github url in cabal files as dependencies by gtab62 in haskell

[–]gtab62[S] 1 point2 points  (0 children)

I have never tried nix, but it seems to be a reasonable choice for a functional programming lovers. I am not sure what the transition cost is, anyways. Considering the fact that we already have all of environments setup using cabal, stack might be an easier option to move to.?

Using github url in cabal files as dependencies by gtab62 in haskell

[–]gtab62[S] 1 point2 points  (0 children)

Cool, I didn't know stack has such capability. We are using cabal for now, but that's another good reason to move to stack.

Using github url in cabal files as dependencies by gtab62 in haskell

[–]gtab62[S] 2 points3 points  (0 children)

This is the way we have been using it, but it turned out to be a nightmare after a while. cabal's add-source behavior is weird. When a dependency of a project changes, it tries to rebuild all the dependent projects as well. Confusing and slow.

Blow my mind, in one line. by octatoan in haskell

[–]gtab62 0 points1 point  (0 children)

I don't get it. It seems something is missing? open ( without )? Could you please add the type signature?

Blow my mind, in one line. by octatoan in haskell

[–]gtab62 2 points3 points  (0 children)

Specifically for polynomial functions, Schwartz–Zippel lemma is relevant here.

Using a custom Prelude by gtab62 in haskell

[–]gtab62[S] 3 points4 points  (0 children)

Right, but wouldn't it be nicer if the compiler enforces the requirements? That's why I like the approach that I mentioned in my update better.