Re:Haskell version of Norvig's spelling corrector
by tromp on Friday December 19, 2014 @12:32PM
(#8773257)
Minor nitpick: the first real line of code
is better written as
This is really syntactic sugar for
using the function
from the typeclass Enum for enumerable types,
and the fact that a string (type String) is just
a list of characters (type [Char]).
[ Parent
| on HN ]
Re:Haskell version of Norvig's spelling corrector
by evincarofautumn on Friday December 19, 2014 @01:09PM
(#8773483)
As long as we’re picking nits…
> I wrote this code putting brevity over readability
Overall, this is not particularly terse, for Haskell code. With all the lambdas, it looks like OCaml! For example, these are equivalent, and I find the latter clearer:
(sortBy (\(_,c1)(_,c2) -> c2 `compare` c1))
sortBy (flip (comparing snd))
Now, it’s not necessarily a bad thing to be explicit, but in cases such as these, it’s less repetitious to just use the standard library functions.
Re:Haskell version of Norvig's spelling corrector
by quchen on Friday December 19, 2014 @01:20PM
(#8773553)
For reverse sorting, there's a type that does specifically that.
sortBy (comparing (Down . snd))
See http://hackage.haskell.org/package/base-4.7.0.1/docs/Data-Or...
Re:Haskell version of Norvig's spelling corrector
by evincarofautumn on Friday December 19, 2014 @06:58PM
(#8775252)
True, but I prefer not to use typeclasses in that way.