... in a limited situation.
I will import the HTTP library into my haskellnet repository. However, the importing process of darcs freezes.
Probably, this occurs because both repositories have same directory name, Network. HTTP contains a patch to create Network directory (adddir Network), but this directory already exists in haskellnet library. So darcs are confused.
Certainly, I can easily import the HTTP files directly (not through darcs pull). But, in such case, there will be two problems.
- I lost all of the history of the works for HTTP
- If some patches are send to either library, it is difficult and annoying to send the paches to other library.
I have an idea to deal with this problem -- modifying the patch manually. But darcs allows such modification?
In naive implementation, IMAP requires same constructor names in different context. For example, RECENT is used at the SEARCH command, STATUS command, and in STATUS response. In this case, I would like to define as follows...
type Mailbox = String data IMAPCommand = STATUS Mailbox [StatusQuery] | SEARCH [SearchQuery] : data StatusQuery = RECENT | MESSAGES | : data SearchQuery = RECENT | SEEN | : data MailboxData = RECENT Integer | SEEN Integer | :
In addition to this, IMAP commands are separated as some groups. For example, UID command is used for SEARCH, FETCH, STORE, and COPY. How can I describe this relation in the type definition?
By using polymorphic variant of OCaml, these can be described easily and elegantly.
In conclusion, such relations may be described using not only type definitions, but also function definitions.
IMAP, Internet Message Access Protocol, is a fairly complecated protocol (comparing with POP3). Its specification can be read as RFC 3501.
I worry about the typing of IMAP commands. In normal protocol, the type of a client command can be written such as `Connection -> Request -> IO Response'. However, IMAP server may also return a status update data.
The server program can notify its clients with a status update untagged data. Assume that there is a client connecting to a server and the server may receive a new mail during the connection, for example. In normal, such newly received mail cannot be read from the client because the connection is established before the reception of the mail. However, the server may notify the client as that `it has a new mail'. Any commands may have such status update data.
Therefore, the type of a IMAP command should be `Connection -> Request -> IO (Response, Maybe StatusUpate)', but such typing will be annoying in many case...
Certainly, such typing can be hidden with StateT or WriterT. But is it clever approach?
BTW, I test the behavior of IMAP with Courier-IMAP, an implementation of IMAP, but it will not send any status update data with a command except NOOP. mmm....
At first, my plan is as follows.
First, I'll collect up some libraries which relates with network. For example, HTTP, MissingH (FTP), HAppS (DNS, HTTP, SMTP), and WASH-MAIL (MIME) are the candidates. Second, I'll implement other lacking protocols such as IMAP. POP3 and SMTP is aready implemented by me (see hazakura project).
And third, I'll fix up the libraries -- API level consistency is important for the programmer. The similar naming and similar API is required.
Finally, I'll set up a kind of test suit. Because the validation for the network behavior is hard to describe, the test will be a text level (local) check of query string, or parser for the peer response.
By now, the status is `collect up'. There are some problems to importing other libraries -- but, the most difficult problem is not coding. It is license problem (sigh).
I also read RFC 3501 and start to implement Network.IMAP.
HaskellNet is a library for network protocols such as SMTP, POP3, IMAP, HTTP, FTP and so on. In this blog, I will write my thought about HaskellNet design and implementation and report the progress of my project.
I write it in advance: I have no confidence for my English skill, so I will make trivial (grammatical) mistakes. In fact, this blog is also for my English training. If you find some mistakes or unnatural phrases, feel free to point them out.
If not, any comments are welcome.
sequence  = ;
sequence (x:xs) = do x' <- x;
xs' <- sequence xs;
return (x' : xs')
It seems that Haskell's ethic for putting a gate between I/O and its referentially transparent and strongly-typed functions means that the concept of
multi-tiered architectures is something of a no-brainer.
There are a few web frameworks and web apps in Haskell - HApps, Flippi... do these map naturally and easily onto multiple tiers?
Are there other examples of multiple-tiered apps for Haskell?
Yesterday, after 1 year of studying Haskell, I tried to write my first program involving I/O. I decided to convert a Perl program that I had written which provides lookup of state names via their 2-letter code and vice-versa. A day later, I had something written, but was worried because all of my functions were using
fmap to pull things out of the IO monad. In other words, my entire library reeked of I/O.
The next day, Cale Gibbard wrote a very nice version of my program which relegated the IO to a single function.
But the thing is, you still have to use my module from the main program with the awareness that the data is coming from an IO source. Now, a basic principle of software engineering is to separate the interface from the implementation. There is no way to use the Haskell implementation of my module without full knowledge that said module is returning me data that is coming from I/O... outside of using something called
unsafeIO which I know nothing about.
why does this matter?
Let's say I have a function which does something to a list of functions of type (String -> String) but one of the functions has to open a file to get its string:
sfnProc :: [(String -> String)] -> [Int]
sfnProc = map (\f -> length f)
so the problem becomes that the one function that returns a string via I/O cannot be used opaquely: the referential transparency of Haskell is killing need for opaque API of software engineering.
outdoes sed and probably Perl too:
check it out it's great for processing huge data files that won't fit in memory.
the study period is finished. no more book learning. let the coding begin.