Rosio Pavoris a blog

OFIOC

My copy of Real World Haskell still hasn’t arrived, so I’ve been making do with Learn You a Haskell, which doesn’t suck as much as you’d expect but obviously stops right before it gets to the important bits. I read most of YAHT at some point in the past, but it isn’t as useful.
My initial impression (that Haskell is elegant as shit in most places but has some warts (like typeclasses) and cops out for IO) is mostly confirmed, though unexpectedly, it turns out you can also do stuff with it.

To wit: tripcodes.
My reason for wanting to implement this has disappeared, so I probably won’t be using it to build a non-moonspeak equivalent to tripper+ or Tripcode Explorer, and it’s really only guaranteed to work for Shiichan tripcodes (whose implementation is broken for arguably negligible values of broken, but broken nonetheless), but as first attempts go, at least it’s a bit more interesting than hello, world or yet another factorial implementation.

It took longer than planned because it uses the Foreign Function Interface to call the C version of crypt, and it’s impossible to find a usable tutorial on how that works.
The upshot of this is that it sacrifices laziness and also isn’t guaranteed to work with every Haskell implementation, though it does work with GHC(i):

cairnarvon@feynman:~/code/haskell$ ghci -lcrypt Tripcode.hs
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :&64; for help
Loading package base ... linking ... done.
Loading object (dynamic) crypt ... done
final link ... done
[1 of 1] Compiling Tripcode         ( Tripcode.hs, interpreted )
Ok, modules loaded: Tripcode.
*Tripcode> tripcode "1fXzap//"
Loading package old-locale-1.0.0.0 ... linking ... done.
Loading package old-time-1.0.0.0 ... linking ... done.
Loading package filepath-1.1.0.0 ... linking ... done.
Loading package directory-1.0.0.0 ... linking ... done.
Loading package random-1.0.0.0 ... linking ... done.
Loading package unix-2.3.0.0 ... linking ... done.
Loading package process-1.0.0.0 ... linking ... done.
Loading package array-0.1.0.0 ... linking ... done.
Loading package haskell98 ... linking ... done.
"MhMRSATORI"
*Tripcode> tripcode "tea"
"WokonZwxw2"
*Tripcode>

(I know my copy of GHC is out of date. Hurray for Debian.)

Don’t forget the -lcrypt flag to actually link the crypt library, and if you want to use this to actually write that tripper+ clone, feel free.

Edit: Vague testing indicates this is actually twenty times slower than tripper+ running under Wine (which is already much slower than many alternatives), so it’s probably not going to be useful as anything but a command-line tripcode converter.

11 Comments

  1. Bobo said,

    > has some warts (like typeclasses) and cops out for IO
    Lol wut? What part of contained side-effects do you not understand?

  2. Cairnarvon said,

    The part where you think it’s not a cop-out.

  3. Anonymous said,

    [b]Christopher[/b]? Is it you?

  4. !7422007532 said,

    it doesn’t work for shiichan tripcodes:
    *Tripcode> tripcode “33DoɣoY”
    “5LCO3KVDZ2″

    it should be “7422007532″.

  5. Cairnarvon said,

    That’s odd. It doesn’t work in GHCi, but it does work if you pass it as an argument to the command line thing.

  6. AnONIx9q9. said,

    hmmm yeah it does… that is odd. and i’ve found out why it does that. if you pass it as an argument on the command line, the characters in the string are:
    [51,51,68,111,201,163,111,89]
    in ghci, the characters in the string are:
    [51,51,68,111,611,111,89]

  7. Anonymous said,

    Ah… the IO encoding is utf8, so everything in ghci is converted into proper codepoints, but argv isn’t. Go figure.

  8. !yxj.rAnDoM said,

    http://ѕ.su/tripcode-search.html

    it seems to be reasonably fast (takes about 6.5 times as long as http://hotaru.thinkindifferent.net/code/trip.c to generate 50000 tripcodes with no regex).

    unless of course you’re using glibc’s (extremely slow) crypt()…

    also, your blog seems to be somewhat broken. certain characters in the “E-mail” and “URL” fields seem to cause problems.

  9. !yxj.rAnDoM said,

    and your blog is pretty broken…
    putting certain characters in the “E-mail” or “URL” fields apparently causes comments to not be posted, but then if you change those fields and try to resubmit the comment it says “duplicate comment detected” or something like that.
    and the way it saves tripcodes in cookies is kinda messed up too. it doesn’t work as a tripcode if you post again without retyping it, which kinda defeats the whole purpose of saving it in a cookie.

  10. Cairnarvon said,

    Your comment was held up by the spam filter, not because WordPress is broken. The thing where it saves your username in cookies really is a result of the WordPress developers being braindead morons, though, but I don’t think I can be blamed for that.

    I’ll write my own blogging software at some point, though probably not until after I find a decent VPS somewhere.

  11. !yxj.rAnDoM said,

    well if the spam filter blocks comments for having certain valid characters in the e-mail and url fields, it is broken.

Post a Comment

RSS feed for comments on this post · TrackBack URL