jump to navigation

Progress – More Erlang 8 March 2008

Posted by Oliver Mason in erlang.
trackback

Erlang practice is slowly moving along. At a speed of about one per day I am currently porting my Java NLP tools over to Erlang. It still takes quite some time getting used to it, especially the flexibility with types.
Everything is a list or a tupel or an atom, so it is sometimes tricky to keep track of what you’re dealing with. Ad-hoc solution: annotate the type.

My implementation of a trie is simply a list, so when looking something up in a trie I pass a list as the first parameter. But what if it’s not a trie-list? Bad things happen within the trie module, far from the place where the actual error is caused. So the exported functions, insert/3 and retrieve/2 now take a tupel rather than a list. The tupel is {trie List}, where the List is what I used to pass previously. But now it is a lot easier to check that the error is actually that the wrong element is being passed.

Advertisements

Comments»

1. ppolv - 11 March 2008

yes, tagging tuples this way is a common erlang idiom.
For example, most functions in OTP tag their responses, to easily distinguish between a valid response {ok,Response} and an error {error,Error}

Indeed, records are compiled by the erlang preprocessor to regular tuples, with the first slot holding the record name, so if you were defined a trie as
-record(trie, {list})
the underling representation would still be similar.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: