[Haskell-cafe] GetOpt

Anton Kulchitsky anton at kulchitsky.org
Thu Apr 27 16:54:44 EDT 2006


Hi Bulat,

thank you very much for such a detailed reply!

>> I just started to study Haskell and it is my almost first big experience
>> with functional languages (except Emacs Lisp and Python). I enjoyed all
>> small exercises and started a bigger business writing a general utility.
>>     
>
> you are my ideal client because we both speak Russian (but not here :) )
>   
Da! :) Spasibo.

> and both interested in large "real-world" applications :)  download
> the http://freearc.narod.ru/FreeArc-sources.tar.gz and enjoy - it's a
> full of Russian comments and it's a real-world program that solves
> many problems that you yet foresee :)
>
> in particular, i also started with vision of my program (it's a
> RAR-like archiver) as a sequence of transformations:
>
> 1) first, a command line translated into the program "job" - it's
> actually business of GetOpt and not very differ from other language's
> implementations
>
> 2) second, this job plus information about files on disk is translated
> into the record of structure of archive being created
>
> 3) third, archive structure translated into the sequence of I/O
> operations
>
> but when i started to do the actual implementation, i realized that
> such pure functional approach is nor appropriate and at the last end
> i wrote the straight imperative program, just using the power of
> Haskell language. moreover, in this process i added to the language
> many imperative constructs that make imperative programming easier
>
>   
I really trying to avoid imperative approach. I do have a terribly big 
experience in imperative programming (by the way, you might know one 
application that I made about 3 years ago. It is Uni-K Sensei for 
windows). Now, I am breaking my previous habits just to think wider and 
more effective.
>> However, I have a problem from the beginning. The utility get some file
>> and convert it to another format. It is a kind of small compiler. It 
>> also accepts many parameters and behaves depending on them. The problem
>> is how to do this neat! How should I write my program to accept and 
>> neatly work with options????
>>     
>
> you can see my solution in Cmdline module - it's one of largest module
> in my program. i don't like the GetOpt interface (it returns a list of
> options what is unusable for high-speed application) so i implemented
>   
Well, I do not care too much about high-speed. My main goal is to write 
a prototype of the language that I am creating. It is a kind of 
Domain-Specific language. I decided to start from a simple thing. A 
converter of pgn files with chess notation to javascript to visualize 
it. Just to have some practice.
> my own option-processing routines, it's just about 50 lines long
> (great demonstration of Haskell power!). all processed options are
> record in one large record that is passed around all the program. if
> you get accustomed to global variables, it's using in Haskell is
> possible but that is not the best way. you can also use implicit
> parameters (at least in hugs and ghc), but this again makes data
> dependencies somewhat non-understandable
>
>   
Thank you very much. I will see this approach as well. I am still pretty 
concern of using records instead of lists.

> btw, i suggest you to use WinHugs for debugging program and ghc for
> final compilation. this makes faster development time together with
> faster final executable. moreover, making your program compatible with
> both environments is almost ensure that it will be compatible with
> coming Haskell standard, Haskell-prime
>   
Thanks again. I do not use Windows any more. I use Mac or different 
Unices. I do use ghc everywhere I work with Haskell. For debugging I use 
ghci. Well, and everything within GNU Emacs.

> returning back to options parsing - there is an interesting
> alternative to GetOpt (which is just mimics corresponding C module) -
> it's a PescoCmd:
>
> http://scannedinavian.org/~pesco/distfiles/pesco-cmdline-2.0.tgz
> http://scannedinavian.org/~pesco/distfiles/pesco-cmdline-2.0.pdf
> http://scannedinavian.org/~pesco/distfiles/pesco-cmdline-man-2.0.pdf
>
>   
Thanks! Very interesting

> i also recommend you to read several other real-world Haskell program
> where you can steal more code and ideas:
>
> http://postmaster.cryp.to/postmaster-2005-02-14.tar.gz
> ftp://ftp.cse.unsw.edu.au/pub/users/dons/yi/yi-0.1.0.tar.gz
> darcs (darcs get --partial http://www.abridgegame.org/repos/darcs/)
> happs (darcs get --partial http://happs.org/HAppS)
>   
Darcs was a little too complicated for me. Thank you for other links.

> and one more interesting source of real-world approach to Haskell
> programming:
>
> http://www.haskell.org/haskellwiki/Hitchhikers_Guide_to_the_Haskell
>
>
>   
Thank you very much, Bulat. Now I see why people say that haskell-cafe 
is the best mail-list! :)

Anton Kulchitsky


More information about the Haskell-Cafe mailing list