2013-03-09

Haskell studies

(LHS => RHS) means LHS is the class context of an entity on the RHS (which may be another class). Must... remember... Superclasses. Check. Multiple class inheritance, ok.
(newtype) compiler implications, not so much. I need to read up and understand (newtype) declarations, better.
Languages that have both prefixes and suffixes, each adding semantic predication to root words are ANNOYING. #english #malay #etc I guess it gets worse with compound suffixes and prefixes. Darn.

At some point I'll get to Kinds. At least, I kinda get the note on kind-signatures of unboxed types (-#) suffix. I also don't quite understand type operators, yet.

Ok, I get functional dependencies. Ok. So subclasses are essentially parameterisations of superclasses. (Perhaps more...)

Taking a peek into (ForeignPtr) and (Ptr).

It's a good reminder that the only way to become fluent in a language is do a lot of I/O. Read, and write. Reading lots of code now.

Sunday. Revising class declarations.

Monday. (Text) for Unicode, (ByteString) for ASCII... or something like that, it says. I'm learning to never use (String) for text processing because the cost of refactoring code from (String) to one of the binary types is just immense. Crap - they haven't implemented -XOverloadedLists yet.

First cupping training

Roads in Taman Desa are really. Shit. And i'm an hour late.
Lost in Subang. Fml. I hate driving without 3G.
(Garmin?) Google Maps is fine. I'm just out of data. Got the wrong billing date.
Back on track.
I seem to have missed only the theory portion. Good.
Cupping coffee: seems like using the same utensils across samples, and rinse pots across sub-samples, contaminates samples and... er... palates.

(later, at a cafe)

Tar!!!! I have it! The flavour of that roast, is TAR!!! :D #macaco (Not sure if it's the same, but Rio Macaco has got an iffy history - "fermented monkey coffee".)

Frydaze

A productive day. Somewhat.

Waiting out Friday traffic past 2300 hours. I'm making some sense of the polymorphic type hinting requirements in Text.Regex.Base.RegexLike now.

Time to get out of here. Kinda figured out Haskell's PCRE type siggies. I'll bet the highway's still jammed. #cheras #friday #midnight

Consulting: giving right answers is fast $. But larger sums are to be made in helping clients discover themselves (i.e. what they want).

Trying to figure out how (Array)s, in Haskell, work.

Learning about the (Enum) class. I need to revise tuples. I don't remember if I ever figured out why their implementation makes singletons and parentheses semantically identical (as well as obviously, morphologically identical). Now this seems relevant, and interesting. The unboxed-array naming-convention in Haskell seems convenient.

2013-03-08

Bad ads

One of my best friends decided to crowdsource an ad. It was horrible. I sent her a dozen points which I thought needed improvement. Hopefully she'll still speak to me in the future.

2013-03-07

De-Kuklewiczing Haskell's Experimental Regex Packages

Consider this a study journal, about me trying to figure out how to use the 'regex-base' front-end for regular expressions in Haskell. (Backstory; Earlier mid-level dive into Text.Regex.PCRE.ByteString.)

The focus of this endeavour to figure out how to use Haskell now turns to work of the author of 'regex-base', 'regex-pcre', and 'regex-tdfa'. Unfortunately for Haskell noobs like me, most of his documentation for these packages assumes that the reader is proficient in reading abstract (read: vague) hints for manipulating Haskell's type system. There are no algorithms provided on an "it just works, with a low POSSIBLE* variance of interpretation," basis.

(* in the modal logical sense, sigh *sic*.)

I'm really trying to figure this out - after all, it seems like he's set up quite a robust system. Below, expect plenty of redundancy without similar Q&A on SO, and other sites. Hopefully by the time I'm done with this exploration, we'll be left with some sort of canonical summary for dummies (God forbid the APIs then change again...).

Of special interest are the manipulation of ByteString types, as such manipulations are obviously much faster than String manipulations (I'm assuming you know the difference between these types, in Haskell).

Let me begin by listing all the relevant resources I've run into over the past week of this.

Well, here's a basic working example with Text.Regex.TDFA and String:
import Text.Regex.TDFA
temp = 
  getAllTextMatches ("foo" =~  "o" :: AllTextMatches [] String)
Here's a similar example with Text.Regex.PCRE and String:
import Text.Regex.PCRE
temp = 
  getAllTextMatches ("foo" =~  "o" :: AllTextMatches [] String)
And, adding one module and changing a type hint in each, lets us use ByteString. Here's the TDFA example:
import Text.Regex.TDFA
import Data.ByteString.Char8
temp = 
  getAllTextMatches ((pack "foo") =~ (pack "o") :: AllTextMatches [] ByteString)
Likewise, the PCRE example:
import Text.Regex.PCRE
import Data.ByteString.Char8
temp = 
  getAllTextMatches ((pack "foo") =~ (pack "o") :: AllTextMatches [] ByteString)
That should get us started. I am going to bed now... this research and writing will continue later.

2012-03-08:

Tear down of AllMatchText usage

.. specifically, along with ByteString and PCRE.
import Text.Regex.PCRE
import Data.Array
import Data.ByteString.Char8

main = return $
  -- all expressions returned by the functions below are (ByteString)s

  {-
  getAllTextMatches 
  ((pack "abcdebxcfgfbycijk") =~ (pack "(b).*?(c)") 
    :: AllTextMatches (Array Int) (Array Int ByteString))
  --  An Array of: 
  --    Arrays, 
  --    containing all matched expressions, 
  --    and their matched subexpressions -}

  {-
  getAllTextMatches 
  ((pack "abcdebxcfgfbycijk") =~ (pack "(b).*?(c)") 
    :: AllTextMatches [] (Array Int ByteString))
  --  A List of: 
  --    Arrays of:
  --      matched expressions, 
  --      and their matched subexpressions -}

  {-
  getAllTextMatches 
  ((pack "abcdebxcfgfbycijk") =~ (pack "(b).*?(c)") 
    :: AllTextMatches (Array Int) [ByteString])
  --  An Array of: 
  --    Lists of: 
  --      matched expressions, 
  --      and their matched subexpressions -}

  {-
  getAllTextMatches 
  ((pack "abcdebxcfgfbycijk") =~ (pack "(b).*?(c)") 
    :: AllTextMatches (Array Int) ByteString)
  --  An Array of: 
  --    matched expressions -}

  {-
  getAllTextMatches 
  ((pack "abcdebxcfgfbycijk") =~ (pack "b.*?c") 
    :: AllTextMatches [] ByteString)
  --  A List of: 
  --    matched expressions -}

  --{-
  getAllTextMatches 
  ((pack "abcdebxcfgfbycijk") =~ (pack "(b).*?(c)") 
    :: AllTextMatches (Array Int) (MatchText ByteString))
  -- An Array of: 
  --  (MatchText)s, i.e. Arrays of:
  --    matched expressions, 
  --        with their (MatchOffset)s 
  --        and their (MatchLength)s
  --    and their matched subexpressions 
  --        with their (MatchOffset)s 
  --        and their (MatchLength)s -}
It turns out that as suspected, there's just too much going on in K's giant type signatures. This is complexified by the use of the Array type - which is morphologically represented by round and square brackets, as if it were composed only of tuples and lists, while being subject to further semantic conventions that require a reading of the documentation of (Array). (Actually, their implemented completely differently from mere ordinary tuples and lists.) Furthermore, K exports all sorts of utility variations for formatting the output of each function... lists-of-arrays, arrays-of-arrays, arrays-of-lists, etc. all representing the same data in different structures. Very muddy. Nevertheless, I guess he's done a good deed by writing the general libraries for all of us.

And then you've got types (MatchArray) and (MatchText) which are woefully, arbitarily named, despite their underlying simplicity and similarity.

The class (Extract) in Text.Regex.Base.RegexLike, really should be exposed at the same layer as the matching functions. :( I'm thinking that it should belong in some (.Internals or .Utilities) module, instead.


2012-03-11

Done. Figured out the Kuklewicz code, at least at the level of using his utility functions. Will have to tidy this post up later, if ever at all.

WIP

WIP

WIP

WIP

2013-03-06

Plasterboard

Learning how to install drywall / gypsum / sheetrock. Apparently there are screw guns, mesh tape, thinset mortar, clips, metal brackets, and wooden skeletons, and drywall tape involved. The rest seems pretty straightforward. I wonder if I will get to implement this someday.

Later, doing some cursory research into small business financing in Malaysia.

Humpdaze

Finally off the highway. Back to corporate life. Wait. Corporate life, starts on the highway...

Call me weird. But sometimes espresso is just better on ice, like whiskey, for the same reasons.

Finally figured out the Macacao... it works long, with a sweet, gooey, brick of pecan pie... (turns out it's not, it's a Peru)

And the next time I turn my head, the girl in the red shoes is gone.

Let's make pasta... how about some... shareholdings spaghettini? :)

A fairly productive day. Redrafted a proposal, including. financial models, did laundry, paid bills, signed up for cupping training and figured out some Haskell regex stuff.

Haskell: Text.Regex.PCRE.ByteString

I'm pausing my study of existing regex libraries; I'm somewhat burnt out by the mess that's out there. For what it's worth, I've figured out a mid-level API use-case for PCRE and ByteStrings, which are processed faster than Strings. I haven't been able to get the equivalent use-case to work for the TDFA package.
{-# LANGUAGE OverloadedStrings #-} 

import Text.Regex.PCRE.ByteString
import Data.ByteString.Char8
  -- For instances of the IsString type class. FTS.
import Data.Array (Array)
  -- Not really needed, unless you want to make certain type signatures
  -- explicit.

-- Gets the before / match / after ByteStrings.
_regexec
  :: IO
       (Either
          WrapError
          (Maybe (ByteString, ByteString, ByteString, [ByteString])))
_regexec = do
  regex <- _regex
  regexec regex "abCdefgbChijklmbCno" 

-- Gets the first match offset and length.
_execute
  :: IO
       (Either
          WrapError (Maybe (Array Int (MatchOffset, MatchLength))))
_execute = do
  regex <- _regex
  execute regex "abCdefgbChijklmbCno"

_regex :: IO Regex
_regex = do
  compiled <- compile compMultiline execBlank "b.(.*?)b."
    -- These compX and execY settings correspond to defaults defined in
    -- Text.Regex.PCRE.Wrap
  case compiled of
    Right regex 
      -> return regex

2013-03-05

Switching regex engines

Here's the plan. Fix module linkage, and new regex usage, then grab brunch.

Headache. Maybe I need to eat. But on perhaps unhealthy point of discipline, I'm going to break only when the new regex engine is in.

Caving in - not eating out yet - but frying eggs.

Suspect food poisoning from watermelon. More fruit. Nap.

Turned out to be just a bit of lying down. Then some exercise to ensure musculoskeletal factors were not too much too blame for nervous aggravation. Bench presses. A short hang on pull-up bar.

Type signatures and RegexLike.

Learning about functional dependency syntax in class definitions. WTF. Talk about nerds - they wrote a user-level convenience like regular expressions, using "advanced type classes", and didn't bother to write an entry-level API. Granted, it just reminds us that the platform retains some immaturity for (inability to speak down to) the larger set of users.

Another apple. Maybe, another nap.

Finally going downstairs for a proper meal, before I keel over.

I wish I was smarter with semantics, and dumber with people.

Feeling like shit. Not sure if sick, or tired, or just stupid.

Went for a short run, for circulation.

Got the day off, to work on code. Woot. As they say.

Found something useful. The RegexLike module. !@#$%^&*(

(Meanwhile... Thousands to Sulu. Woohoo.)

Depressed, by the amount of work that remains undone.

Had a look at the pcre-light package's documentation - its limitations do not look promising, but perhaps I am missing the point.

After reading the first few lines of an article on Thompson NFAs, I'm looking into the regex-tdfa package. POSIX, but with GNU extensions. We're going hipster now.

After about three days of fucking around with this, I give up. I simply don't feel that I have the emotional energy to continue to pursue this, given the limitations on my time. I will just still to the stock Text.Regex for now. Which is technically fine, since I'm only using regex for meta-programming at this stage.

Last ditch for now - IRC. I should probably use this earlier in my research cycles.

Maybe it's time I retreated to JavaScript FWIW. LOL

Had a good day off, dwelling on the painful limit of my ability to comprehend strange languages. Back to hacking that coffee shop.

Tempted to just reinstall the good old LAMP server and use CakePHP again. Hehe. Maybe I should.

Wondering again what will happen to GHC after SPJ.

Post supper of fish, and orange, washed down with tea, I am forking regex development to another folder, and giving it a higher priority than Doof development. Let's see if this is feasible as a project to learn how to properly use Cabal, etc.

So much work to be done. In different modes. This mind must meditate slowly to transform, between roles.

2013-03-04

Mondaze

6am up, 6:30am first jam, 110 minutes between bed and breakfast. Brilliant. Next time we wake at 5:30am to benchmark. In Bangsar now.

8:30am crowd at Bangsar McDonalds is very well behaved. Quiet and meditative. It's like a packed library.

What a difference ten minutes makes. It's all loud and chatty now.

And then it's all quiet again.

9am meeting. Everytime I sit down and tell a foreigner what I know about Malaysia, I depress myself. What little I know.

10pm. Done with a day of exploring incorporation, and locations. Lock key, load gas, hit the highway, time to go home to code.

Someone wants to invest 100-300k in Malaysia. What asset class, they ask?
I wiped out 80k on a trading experiment over the past 6 months. (I only gamble with what I can afford to lose, and the gamble was really to figure out how many things I could do at once without losing track of them.) I don't actually know what's fundamentally sound or not on the KLSE, right now, as I haven't been keeping track.

So, are you feelin, lucky? ^_- This conversation doesn't end here, of course...
Why are hipsters everywhere?
Trends fall. Others take their place. The shadows never break - hipsters are the shadows.
0228 hours. Tired. But it's the perfect time to get back to my own work.
0237 hours. Too late to make much progress. Bed time. No early mornings tomorrow. Whee.

2013-03-03

Economics of partying

Party? (Cost of fuel + computational/cognitive requirement for driving + time lost ) * (anticipated value of conversation) < 0 #stayHomeAndStudy

Post exercise, I actually feel a lot better. Wondering if it's worthwhile to drive over to KL for a 6pm party, the work at McDs, sleep in my car, and go for the 9am meeting. Sounds like a plan. Game on.

Knackered?

You don't know me, babe... I can sleep anywhere... hehe... as long as I get sleep. It's not a business meeting, so I don't care about presentation. Just some visiting friend of a friend from INSEAD who wants to meet local people for... I don't know, maybe information. Hey, I might not even bother to sleep before the meeting... I just got up at 2pm. The meeting's at 9am... it'll be just like a late night ;)

Halitosis? Coffee usually does the trick. It's a meeting over coffee. Other acidic crap like diet cola tends to keep things neutral. But I could be sorely mistaken!

Ended up back home for studies anyway. But I did figure out that the Bangsar swimming pool is a good place for a shower after 9:30am. After a lot of conversational seeding for an imaginary company, studying regex.

The maximisation of my time on earth is far less interesting, than the study of cognition, while I accidentally remain alive. Of course it is lonely, having few colleagues in this frame of mind, but I'm determined to not-be-a-whiner, and to make do with a few fucks, wage work, and casual chit-chat! That is, what it is to be a member of society.

War in Sabah

We're under invasion. Soldiers/police are dying.

Is this all an excuse to call another Emergency before there can be elections?

Police: uphold the lawfulness of the citizenry. Military: uphold national boundaries. I CAN HAZ SEPARATION OF CONCERNS?! #malaysia

Stop praying, and kick some tush.

Stop praying, and intervene.

If you care, stop praying, and do something. (I don't really care for now, but if I did, I would do something, not -pray- about it.) :P

The punditry is out in force. I always did say, "call me when there's a war." LOL. But I'm still not emotionally engaged; not yet.

Realpolitique suggests that everything done in their favour.