[Haskell-cafe] Re: Ready for testing: Unicode support for Handle I/O
Paolo Losi пишет: wouldn't be semantically correct for a binary handle to return [Word8]? Wouldn't it be more correct to separate binary IO, which return [Word8] (or ByteString) and text IO which return [Char] and deal with text encoding? IIRC that was done in Bulat Ziganshin's streams library. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Timing difference
Aai пишет: Hi Bulat, That I (can) understand, but of course the main question is: is point free in (some/several/all) cases faster than the more readable lambda construction? That's to say when executed in GHCi. I noticed this behavior before (pity I haven't other examples at hand). In prog. lang. J ( http://www.jsoftware.com/index.html ) I see the same behavior difference with tacit (like point free) and explicit programming: tacit being faster in several (not all) occasions. You should write cleanest code. Optimize only when absolutely necessary (and in this case you'll definetly will use a compiled version instead of interpreted). -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: hGetContents and lazyness
Micah Cowan [EMAIL PROTECTED] writes: Max Vasin wrote: Hello, haskellers! Suppose we have function (it filters package filenames from apt Packages file): getPackageList :: FilePath - IO [FilePath] getPackageList packageFile = withFile packageFile ReadMode $ \h - do c - hGetContents h return $ map (drop 10) $ filter (startsWith Filename:) $ lines c -- (1) where startsWith [] _ = True startsWith _ [] = False startsWith (x:xs) (y:ys) | x == y= startsWith xs ys | otherwise = False When, I apply it to a Packages file I (surely) get an empty list. This is an expected result due to lazyness of hGetContents. Combined with the fact that you're not evaluating its non-strict result until after the file handle has been closed, yes. Your current set of IO actions is probably similar to: . open file . process file . close file . use results from processing the file. where the first three steps are all handled by your getPackageList. To avoid either getting incomplete (or empty) results, or having to strictify everything with $!, it'd be better for you to use a process more like: . open file . process file . use results from processing the file. . close file probably by moving the withFile outside of getPackageList, to wrap a function that prints the results after they've been obtained. The function passed to withFile should generally include all the processing related to the file and its results, I believe. Yes. Probably I should leave closing file to the GC and use readFile, this seems to be the simplest way. I tried changing line (1) to return $ map (drop 10) $ filter (startsWith Filename:) $! lines c The $! forces strictness, but since it's deep in the result, it isn't evaluated until it's too late. Chaning it to return $! map (drop 10) $ filter (startsWith Filename:) $ lines c makes getPackageList function return several (but not all) filenames. I think we'd need to see the actual input and expected output, to understand what's going wrong here. It worked fine for me, for small tests. The gzipped example file is here: ftp://ftp.debian.org/debian/dists/lenny/contrib/binary-i386/Packages.gz By the way, it's good policy to always post complete, runnable examples. Requiring anyone who wants to help you to write additional code just to get it to run decreases the chances that someone will bother to do so. Sorry. I've just omitted module imports: import Control.Monad (filterM, mapM) import System.IO (withFile, IOMode (ReadMode), hGetContents) import qualified System.Posix.Files as SPF (isDirectory, getFileStatus) Running in GHCi: GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. Prelude :load Foo.hs [1 of 1] Compiling Foo ( Foo.hs, interpreted ) Ok, modules loaded: Foo. *Foo getPackageList Packages = mapM_ putStrLn 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 unix-2.3.0.0 ... linking ... done. pool/contrib/a/acx100/acx100-source_20070101-3_all.deb pool/contrib/a/alien-arena/alien-arena_7.0-1_i386.deb pool/contrib/a/alien-arena/alien-arena-browser_7.0-1_all.deb pool/contrib/a/alien-arena/alien-arena-server_7.0-1_i386.deb pool/contrib/a/alsa-tools/alsa-firmware-loaders_1.0.16-2_i386.deb pool/contrib/a/amoeba/amoeba_1.1-19_i386.deb pool/contrib/a/apple2/apple2_0.7.4-5_i386 *Foo Printed list of package files is incomplete. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] hGetContents and lazyness
Hello, haskellers! Suppose we have function (it filters package filenames from apt Packages file): getPackageList :: FilePath - IO [FilePath] getPackageList packageFile = withFile packageFile ReadMode $ \h - do c - hGetContents h return $ map (drop 10) $ filter (startsWith Filename:) $ lines c -- (1) where startsWith [] _ = True startsWith _ [] = False startsWith (x:xs) (y:ys) | x == y= startsWith xs ys | otherwise = False When, I apply it to a Packages file I (surely) get an empty list. This is an expected result due to lazyness of hGetContents. I tried changing line (1) to return $ map (drop 10) $ filter (startsWith Filename:) $! lines c or return $ map (drop 10) $! filter (startsWith Filename:) $! lines c with no success. Chaning it to return $! map (drop 10) $ filter (startsWith Filename:) $ lines c makes getPackageList function return several (but not all) filenames. What I'm missing? And how can I fix my code? -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FW: Treating command-line arguments as a Haskell expression
2007/12/24, Simon Peyton-Jones [EMAIL PROTECTED]: Would someone familiar with the command-line-parsing libraries care to help Krassimir? AFAIU Krassimir's needs, hs-plugins will help him (function eval). -- WBR, Max Vasin JID: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell newbie questions
2007/9/22, Hugo Pacheco [EMAIL PROTECTED]: Hi all, If I want to write some function that will dynamically create a selection function according to its arguments and do something with it. You cannot dynamically create function, all you can is to create it at compile-time (that's what TH lets you to do). However, is there a possible way to generate Haskell functions from TH without having to instanciate its arguments? First of all, how do you intend to use your fsel function? In fact if we ignore stage restirctions expression $(sel x y) will have different types depending on fsel parameters. Even if we can generate code at runtime, we cannot assign a type to the $(sel x y) expression (except something like Dynamic, but doubt if it makes sence). Even if we can assign a type to the $(sel x y) expression, the $(sel x y) (x, y) expression is well-typed only if $(sel x y) has type (a, b) - c. -- WBR, Max Vasin JID: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: xmonad 0.3
2007/9/7, Dan Piponi [EMAIL PROTECTED]: That depends on your definition of this kind. I meant window manager. I.e. a porgram which manages window size, placement, focus, decorations, etc. http://en.wikipedia.org/wiki/LiteStep This is a shell (a replacement for explorer), not a window manager. In Windows there is no such thing as window manager (it's functionality is built-in into Windows itself). -- WBR, Max Vasin JID: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: xmonad 0.3
2007/9/5, Peter Verswyvelen [EMAIL PROTECTED]: Looks really nice, but if I understand it correctly it is specific for X, so does not work on Windows? This kind of programs is impossible in Windows. Of cause you can use X server for Windows and xmonad as window manager with X server. If so, would it be possible to integrate this into GTK2HS so it works as a docking manager inside an application? First of all, gtk is a cross platform toolkit and gtk2hs is just a wrapper. It will be better to implement a docking manager in C to let whole gtk community use it. -- WBR, Max Vasin JID: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] defining mapPairs function
2007/8/30, Neil Mitchell [EMAIL PROTECTED]: Hi mapPairs :: (a - a - a) - [a] - [a] mapPairs f [x] = [x] mapPairs f [] = [] mapPairs f (x:xs) = f x (head xs) : mapPairs f (tail xs) It looks like it works, but you can get a better version by changing the last line: mapPairs f (x:y:zs) = ... - left as an exercise, but no need for head or tail. And you can get less equations if you replace first two equations with mapPairs f x = x and place it after Neil's. -- WBR, Max Vasin JID: [EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: HSH 1.2.0
Thomas == Thomas Hartman [EMAIL PROTECTED] writes: Thomas Furthermore (as the above messages suggest and locate confirms), I Thomas seem to have mtl already Thomas I took a wild guess and tried specifying this with ghc -i Thomas like Thomas sudo runghc -i/usr/lib/ghc6-mtl-dev Setup.lhs configure Thomas and sudo runghc -i/usr/lib/ Setup.lhs configure Thomas but no dice. Thomas *** Thomas [EMAIL PROTECTED]:~/haskellInstalls/hsh$ locate libghc6-mtl-dev Thomas /home/thartman/libghc6-mtl-dev_1.0-3_i386.deb Thomas /usr/lib/libghc6-mtl-dev Thomas /usr/lib/libghc6-mtl-dev/register.sh Thomas /usr/lib/libghc6-mtl-dev/unregister.sh Thomas /usr/share/doc/libghc6-mtl-dev Thomas /usr/share/doc/libghc6-mtl-dev/changelog.Debian.gz Thomas /usr/share/doc/libghc6-mtl-dev/copyright Thomas /var/lib/dpkg/info/libghc6-mtl-dev.list Thomas /var/lib/dpkg/info/libghc6-mtl-dev.md5sums Thomas /var/lib/dpkg/info/libghc6-mtl-dev.postinst Thomas /var/lib/dpkg/info/libghc6-mtl-dev.prerm As you have built ghc6.6 from sources I think that you also need to build all haskell libs from sources. So, do $ apt-get source libghc6-mtl-dev $ cd haskell-mtl-or-whatever-dir-is-named $ runhaskell Setup.lhs configure $ runhaskell Setup.lhs build $ sudo runhaskell Setup.lhs install Another way is to take ghc6 and all haskell libs from fiesty. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How to use infinite lists to define the list of all negative integers
Bahtijar == Bahtijar Vogel [EMAIL PROTECTED] writes: Bahtijar Hi, How am I supposed to use infinite lists to define Bahtijar the list of all negative integers? negs = [-1,-2..] -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: nested maybes
Maybe has a Monad instance, so you can write this as follows (untested): exists str wmap = boolFromMaybe exists' where exists' = do x - Map.lookup (sort str) wmap find (== str) (snd x) boolFromMaybe (Just _) = True boolFromMaybe Nothing = False import isJust boolFromMaybe = isJust -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: snd and tuples of various sizes...
Mattias == Mattias Bengtsson [EMAIL PROTECTED] writes: Mattias On Thu, 2007-02-01 at 21:01 -1000, Tim Newsham wrote: instance Second [a] a where snd [] = error don't got none snd (x:y:xs) = y Mattias Would'nt that instance mean this: snd [] produces error Mattias snd [x] gives [] No. It is non-exhaustive pattern. In fact this is needed: instance Second [a] a where snd (_:y:_) = y snd _ = error don't got none Mattias I'd implement it something like this (if this works?): Mattias instance Second [a] (Maybe a) where snd [] = Nothing snd Mattias [x] = Nothing snd (x:y:xs) = Just y Well, we also can define: class SafeSecond a b | a - b where ssnd :: (Monad m) = a - m b instance SafeSecond [a] a where ssnd (_:y:_) = return y ssnd _ = fail don't got none main = do print $ (ssnd [1, 2, 3] :: Maybe Int) print $ (ssnd [1] :: Maybe Int) -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Default (or empty) values
Hello all! Let data Book = Book { authors :: [String], title :: String, editor:: Maybe String, edition :: Maybe String, volume:: Maybe (Int, Int), -- e.g. volume 1 of 3 publisher :: String, year :: Int, pages :: Int } and convertBook :: Map String String -- a map from field names to values (string representation) - Maybe Book convertBook takes info about book from some external source (e.g. a BibTeX database) and returns Just book value or Nothing (if convertion failed). Fields of the Book datatype which are not (Maybe a) are required to be present. convertBook looks like convertBook = (rq title (\b v - b { title = v }) . rq publisher (\b v - b { publisher = v }) . ... ) (Just $ Book [] Nothing Nothing Nothing 0 0) I don't like the `(Just $ Book [] Nothing Nothing Nothing 0 0)' part, I would prefer instead someting like `empty :: Book'. So I define class Empty e where empty :: e But still I have to emplement instances by hand. There are a number of approaches to automatically derive instances (TH, generic classes in GHC, drift). What would you recommend using in this case? Or may be it would be better to drop out Empty and use something else? TIA -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Default (or empty) values
Pedro == Pedro Baltazar Vasconcelos [EMAIL PROTECTED] writes: Pedro On Wed, 17 Jan 2007 15:58:04 +0300 Pedro Max Vasin [EMAIL PROTECTED] wrote: Hello all! Let data Book = Book { authors :: [String], title :: String, editor :: Maybe String, edition :: Maybe String, volume :: Maybe (Int, Int), -- e.g. volume 1 of 3 publisher :: String, year :: Int, pages :: Int } One suggestion: why not make the Book type more general, e.g. a list of labeled fields: data Label = Author | Title | Editor | type Field = String newtype Book = Book [(Label,Field)] Pedro The idea is that e.g. multiple authors would be represented Pedro by multiple entries with an Author label and optional Pedro fields can be omitted. Then the empty book is simply It does not enforce presence of required fields at type level. Also it does not enforce that fields pages and year are Int. And I want to move as much checks to compile time as possible. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Default (or empty) values
Colin == Colin DeVilbiss [EMAIL PROTECTED] writes: Colin On 1/17/07, Max Vasin [EMAIL PROTECTED] wrote: Fields of the Book datatype which are not (Maybe a) are required to be present. Colin This doesn't actually answer your question, but if those Colin fields are really required and you want to avoid the Colin possibility of a default value sneaking into the program Colin through a bug, you may prefer to use undefined instead of a Colin non-bottom value for the required fields. That is, Colin Book undefined undefined Nothing Nothing Nothing undefined Colin undefined undefined Hmm that's interesting... Colin (lots of typing, but if a bug slips in and you get a Colin partially-defined book into the guts of the program, you'll Colin die instead of silently using invalid data.) class Empty e where empty :: e But still I have to emplement instances by hand. Colin What would the strategy be here for automatically defining Colin the instances? For example, what are the Empty instances Colin for Colin data Foo = Bar | Baz | Quux data Foo2 = Bar2 Int | Baz2 Colin String | Quux2 (Maybe String) In my program (a BibTeX analog) Empty instances will be defined for datatypes representing bibliography entries which will have only one value constructor (records can't be used with newtype AFIAK). So for data Foo = Foo t1 t2 ... tN instance Empty Foo where empty = Foo (empty :: t1) (empty :: t2) ... (empty :: tN) Or may be it would be better to drop out Empty and use something else? Colin I see no inherent problem with Empty, just with the Colin automated instantiation. Then again, I'd be tempted to Colin wait to define Empty until I saw the second or third Colin instance of its use. There will be datatypes representing books, articles, thesis, reports, etc. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Default (or empty) values
Henning == Henning Thielemann [EMAIL PROTECTED] writes: Henning On Wed, 17 Jan 2007, Max Vasin wrote: Hello all! Let data Book = Book { authors :: [String], title :: String, editor :: Maybe String, edition :: Maybe String, volume :: Maybe (Int, Int), -- e.g. volume 1 of 3 publisher :: String, year :: Int, pages :: Int } and convertBook :: Map String String -- a map from field names to values (string representation) - Maybe Book convertBook takes info about book from some external source (e.g. a BibTeX database) and returns Just book value or Nothing (if convertion failed). Fields of the Book datatype which are not (Maybe a) are required to be present. convertBook looks like convertBook = (rq title (\b v - b { title = v }) . rq publisher (\b v - b { publisher = v }) . ... ) (Just $ Book [] Nothing Nothing Nothing 0 0) I don't like the `(Just $ Book [] Nothing Nothing Nothing 0 0)' part, I would prefer instead someting like `empty :: Book'. So I define class Empty e where empty :: e But still I have to emplement instances by hand. There are a number of approaches to automatically derive instances (TH, generic classes in GHC, drift). What would you recommend using in this case? Or may be it would be better to drop out Empty and use something else? Henning Using a record with named fields is good style, as you Henning pointed out later. Stick to it! Why do you need a type Henning class? What about simply Henning empty :: Book empty = Book [] Nothing Nothing Nothing Henning 0 0 Well the type class is not necessary, a TH function generating an empty value for given datatype. OTOH convertBook can be rewritten (using type class) as: convertBook = (rq title (\b v - b { title = v }) . rq publisher (\b v - b { publisher = v }) . ... ) and it will be used like 'convertBook empty'. I like this way more since convertBook looks more declarative. Henning For updates empty { title = new title } is perfectly Henning ok. Henning You can also let undefined fields undefined. In Henning Book {} This will be enough if there were no optional fields. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Default (or empty) values
Pedro == Pedro Baltazar Vasconcelos [EMAIL PROTECTED] writes: Pedro On Wed, 17 Jan 2007 16:57:54 +0300 Pedro Max Vasin [EMAIL PROTECTED] wrote: It does not enforce presence of required fields at type level. Also it does not enforce that fields pages and year are Int. And I want to move as much checks to compile time as possible. Pedro You can combine the two solutions: a product-type of Pedro required fields plus list of optional fields. You're right Pedro that you lose the typing constraints on fields. I probabily Pedro woudn't bother, but you might be able to recover that with Pedro the type-classes or GADTs (?). I have only a very basic understading of what GADTs are :-( Pedro But more important: it sounds to me like you have two Pedro conflicting requirements: one the one hand you want to have Pedro required fields (presumability those that were not Maybe Pedro types) but on the other hand you want an empty book Pedro (i.e. with for title, etc.). I want to get as strict type checking as possible while writing as little code handling Book as possible. The empty value is needed only to start with when analising external represenation. And as suggested by Colin DeVilbiss and Henning Thielemann it will be better to use undefined for required fields. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: The Future of MissingH
Bulat == Bulat Ziganshin [EMAIL PROTECTED] writes: Bulat Hello Max, Hello, Bulat Monday, November 27, 2006, 10:04:15 AM, you wrote: A small addition: some GPLed libraries (libstdc++ AFAIK) allow linking with proprietary software by adding clause to lisence which relaxes GPL requirements. Bulat a GPL license text is the same for any GPLed software, Bulat otherwise it cannot be called GPL :) this should be a Bulat LGPL. also there are many double-licensed libs. you can Bulat find details about this in LGPL and GPL pages of wikipedia Bulat (where i've read this) from /usr/share/doc/libstdc++6/copyright: The libstdc++-v3 library is licensed under the terms of the GNU General Public License, with this special exception: As a special exception, you may use this file as part of a free software library without restriction. Specifically, if other files instantiate templates or use macros or inline functions from this file, or you compile this file and link it with other files to produce an executable, this file does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: The Future of MissingH
Benjamin == Benjamin Franksen [EMAIL PROTECTED] writes: Benjamin Bulat Ziganshin wrote: Friday, November 24, 2006, 7:32:55 PM, you wrote: Josef Svenningsson posted a comment on my blog today that got me to thinking. He suggested that people may be intimidated by the size of MissingH, confused by the undescriptive name, and don't quite know what's in there. And I think he's right. first, is it possible to integrate MissingH inside existing core libs, i.e. Haskell libs supported by Haskell community? i think that it will be impossible if MissingH will hold its GPL status. i think that such fundamental library as MissingH should be BSDified to allow use it both in commercial and non-commercial code Benjamin I hate to be nitpicking but GPL is not only compatible Benjamin with but encourages commerce in general and commercial Benjamin software in particular. It is incompatible with Benjamin proprietary software. There's a difference. A small addition: some GPLed libraries (libstdc++ AFAIK) allow linking with proprietary software by adding clause to lisence which relaxes GPL requirements. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: best Linux for GHC?
Yes, but I wouldn't recommend installing rpms in debian-based system (although, it can work perfectly). GHC 6.6 is in Debian unstable (and should be in Ubuntu 6.10 or development branch). Ubuntu universe repositiry is automatically updated from Debian repos thus being one of the largest repos for Linux. PS: I'm using Debian testing/unstable. -- WBR, Max Vasin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: what GUI library should i select?
On linux you should use your package manager (whenever possible), not binaries from the site (or compile it yourself). -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: StateT and modify
Peter == Peter Steiner [EMAIL PROTECTED] writes: Peter On 11/8/06, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Peter, Wednesday, November 8, 2006, 1:48:24 PM, you wrote: i would like to be able to debug what's happening inside the modifier function. that's why i want to be able to use a modifier that's in the IO monad for debugging there is 'trace' function which don't needs IO monad Peter thanks. i am aware of trace, but the potentially messed up Peter execution order makes it very hard for me to get useful Peter information out of the resulting trace. besides, IO will Peter scale to more elaborate logging mechanisms later on... If all you want from IO is logging why not just use MonadWriter? -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: More documentation: languages written in Haskell
Donald == Donald Bruce Stewart [EMAIL PROTECTED] writes: Donald I noticed today that although we have a list of most Donald applications written in Haskell, nowhere was there Donald collected a page of perhaps our best use case for Haskell: Donald for implementing compilers and interpreters! Donald So here's a new 'libraries and tools' category page: Donald http://haskell.org/haskellwiki/Libraries_and_tools/Compilers_and_interpreters Donald If you know of a compiler or interpreter written in Donald Haskell, (I think at least a few people on this list have Donald written one or two themselves ... ;) please add it to the Donald list. I have no login at haskell.org, so I post here. There is a Curry compiler implemented in Haskell: The Münster Curry Compiler (http://danae.uni-muenster.de/~lux/curry/). -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: UTF and Parsec
John == John Ky [EMAIL PROTECTED] writes: John Hi,I'm interested in using Parsec to parse utf-8 files and John do some processing and output a utf-8 document. Is there John anything I should be aware of? Does GHC handle all the John utf-8 stuff automatically? What does it mean when I find John that parsec is picking up  at the beginning of the All strings in Haskell are unicode - you only have to input them correctly :-) I've used Streams (somewhere at haskell.org) library to read files in UTF-8 and then parsed read data with Parsec. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell compiler from a USB Stick?
Jón == Jón Fairbairn [EMAIL PROTECTED] writes: Jón Bulat Ziganshin [EMAIL PROTECTED] writes: Hello David, Tuesday, October 3, 2006, 2:17:33 PM, you wrote: Does anyone know of a Haskell compiler that will run from a USB stick? i'm ôäüùûå sure Jón Блым? almost %-) Bulat accidently switched keyboard layout to russian :-) -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Map.genericSize
Bulat == Bulat Ziganshin [EMAIL PROTECTED] writes: Bulat Hello Christian, Bulat Friday, September 29, 2006, 1:02:07 PM, you wrote: Map (and Set) use (unboxed) Int internally. So bigger Maps and Sets are not possible. Bulat interfaces has their own lives :) someone can write DiskMap Bulat library which allows to old more data but has the same Bulat interface as Data.Map It's a job for a collections framework, isn't it? -- WBR, Max Vasin. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
[Haskell-cafe] Re: Getting the latest
Lyle == Lyle Kopnicky [EMAIL PROTECTED] writes: Lyle My question is, when I do 'make install', will it just overwrite Lyle the version (6.4.1) I already have? Or will they go in separate Lyle places? This depends on the prefix you configured sources with (/usr/local by default). Lyle I have no idea how it decides where to go. Right now ghc Lyle 6.4.1 is in /usr/local/bin/ghc. After I 'make install', will it Lyle be ghc 6.5? I don't want to screw up the installed package so it Lyle can't be updated later. It should be :-) PS: It is better to build a custom package (dh_make will help you). -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Is Haskell a 5GL?
Ch == Ch A Herrmann [EMAIL PROTECTED] writes: Ch Hi, Hello, I'd say very strong, lots of times a where is used thats making use of laziness. Ch I don't agree: where is often only used to program in a top-down Ch style I would say in a more declarative style, the where is closer to thinking of the program as a set of equations (as opposed to let). -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Is Haskell a 5GL?
Ch == Ch A Herrmann [EMAIL PROTECTED] writes: it's a BottomthGL language :) Ch That's a religious statement. I was looking for some strong Ch arguments for the nonbelievers that Haskell is a 5GL. But what about nonbelievers in language classification by generation? As already mentioned you can write algorithms in Haskell (3GL), embed a DSL in it and write a program in that DSL or in several DSLs (4GL). AFAIK Mathematica is not a logic programming language, thus all its features can be implemented in Haskell as library, will be Haskell a 5GL in this case? -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Defining show for a function type.
Johan == Johan Grönqvist [EMAIL PROTECTED] writes: Johan I am a haskell-beginner and I wish to write a Forth-like Johan interpreter. (Only for practice, no usefulness.) Johan I would like use a list (as stack) that can contain several Johan kinds of values. Johan data Element = Int Int | Float Float | Func : Machine - Johan Machine | ... Johan Now I would like to have this type be an instance of the class Johan Show, so that I can see what the stack contains in ghci. Johan deriving Show is impossible as Func is not instance of Johan Show. Can I make it instance of Show? I just want to define Johan something like Johan show (Func _) = Function, cannot show err, why not just write instance Show Element where ... show (Func _) = Function, cannot show E.g: data Foo = Bar | Foo (Int - Int - Int) instance Show Foo where show Bar = Bar show (Foo _) = Func! main = do putStrLn $ show Bar putStrLn $ show $ Foo (+) -- WBR, Max Vasin. NP: Nothing playing right now ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Using of C constants in Haskell sources; Determining compilation environment (Unix vs Windows)
Bulat == Bulat Ziganshin [EMAIL PROTECTED] writes: Bulat Hello Haskell, what is a best way to bring C constant (defined Bulat in header file) into the Haskell source? Haskell project is Bulat cabalized and should work with both Win and Unix while the Bulat constants are OS-specific. the best way i found at this moment Bulat is to use the following scheme: Bulat mmap.h: Bulat #if defined(mingw32_HOST_OS) || defined(__MINGW32__) || Bulat defined(_MSC_VER) #else INLINE int const_MAP_FILE( void ) Bulat { return MAP_FILE; Bulat } Bulat #endif Bulat mmap.hs: Bulat #if defined(mingw32_HOST_OS) || defined(__MINGW32__) || Bulat defined(_MSC_VER) #else foreign import ccall unsafe Bulat mydefs.h const_MAP_FILE mAP_FILE :: CInt #endif Well, the haskell source is processed with cpp, so if constants are #define'd (and not declared with `const') you can use preprocessor macros to generate Haskell code (yeh, I know it's silly, but why not?). -- WBR, Max Vasin. NP: Nothing playing right now ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: how to apply a function which returns IO() to a list?
developer == developer [EMAIL PROTECTED] writes: developer Hi, I have this function which write a file: developer writeHtml b x y = do writeFile (b ++ .html) (htmlCode b x developer y) developer i need to apply to each member of a given list: developer the way i always try to codify functions in haskell is developer allways the same, the most primitive one and i think i cant developer use it here. developer writeList [] = ??? developer writeList (x:xs) = (writeHtml x) ??? writeList [] = return () writeList (x:xs) = do writeHtml x writeList xs -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: calling haskell from C++
Vladimir == Vladimir Portnykh [EMAIL PROTECTED] writes: Vladimir Hello ALL, I am very new to Haskell and my question might Vladimir appear very basic sorry about it in advance. I have a C++ Vladimir application and I would like to be able to launch Haskell Vladimir interpreter (lets say GHC) supplying the Haskell code (in a ghci - not ghc. Vladimir file ) to be interpreted from it. The Haskell program Vladimir generates some output and I would like to use this output in Vladimir my C++ program. Do you have any simple example to help me, Vladimir please? Hmm. That depends on what the output of the haskell program is. If I understand you corrrectly the output of the program is what it writes to the stdout. In this case you'll can do the job using popen(2) (or whatever is available in your OS) - you create process to run 'runhaskell file.hs' and redirect its stdout to a pipe. There is also an FFI which allows you to call functions written in Haskell from other languages. In this case your Haskell program must export C-level API to be used from C++. Or, and of cause you can use IPC to connect your programs. -- WBR, Max Vasin. NP: ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: develop new Haskell shell?
Brian == Brian Hulley [EMAIL PROTECTED] writes: Brian Some other possibilities are: Brian 1) Every command returns a pair consisting of result and return Brian code IMHO the distinction between command's output (to stdout and stderr) and its return code is one of the faults in UNIX shells. Nothing, but log should be written to stdout by command, and stderr should be useless if we use exceptions (I'm not quite sure). Brian 2) Use exceptions instead of stderr instead of stderr and return code. The return code of `test' is in fact its result. Brian 3) Use a more complicated monad It may still be a good idea to take the top 20 unix utils and code them as native haskell functions and see how far that goes. I know there are some existing libraries that deal with basic stuff like mv, etc. Has anyone implemented grep, find, etc? Brian This is also how I would start because it would allow all the Brian control flow/ ease of use issues to be explored just using GHCi Brian / Hugs etc before tackling the problem of how to get binaries Brian to interface with the shell. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell] Re: lhs2TeX-friendly emacs mode?
Conal == Conal Elliott [EMAIL PROTECTED] writes: Conal Is there a Haskell emacs mode that works well with lhs2TeX? Conal Specifically (a) treating \begin{spec} ... \end{spec} like Conal \begin{code}... \end{code}, and (b) coloring inline code Conal (|expr|) and maybe inline verbatim (@expr@) as Haskell Conal rather than LaTeX code. May be mmm-mode will help you, I haven't tried the combination mmm-mode+latex-mode+haskell-mode. AFAIU it should work (I used mmm-mode with cweb mode to highlight latex and c code simultaneously). -- WBR, Max Vasin. ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
[Haskell] Re: lhs2TeX-friendly emacs mode?
Conal == Conal Elliott [EMAIL PROTECTED] writes: Conal Hi Max. Hi Conal, Conal Thanks for the mmm-mode suggestion. It sure looks Conal like it should help, but I didn't see any effect when I tried Conal it. Would you mind sharing the emacs lisp you use with it? Well, to see any effect you have to select submode class (C-c % C-c). I used CWEB submode class which shipped with mmm-mode. Defining new submode is pretty easy - look at the documentation which comes with mmm-mode and examples (on my machine they are in /usr/share/emacs/site-lisp/mmm-mode/). -- WBR, Max Vasin. ___ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
Re: Dumb guy needs help
Davey == Davey dude [EMAIL PROTECTED] writes: Davey Im new to Haskell, hugs in particular, and was hoping you could Davey help me solve a problem. It should be pretty easy. I have to Davey use hugs to create an expression data Exp = Plus Exp Exp| Sub Davey Exp Exp| Mult Exp Exp| Power Exp Exp | Number [Int] to define Davey a constant ex1 :: Exp that represents the function ((3*4) + Davey (2*(12^2))) - 2. Exp is an expression where numbers are Davey represented by a list of digits (540 is [5,4,0]). Got any Davey ideas. Any help is greatly needed! Expression ((3*4) + (2*(12^2))) - 2 consists of 2 subexpressions: ((3*4) + (2*(12^2))) and 2 connected by the `-' operator, so ex1 = Sub ex1_2 2 where ex1_2 is an Exp representing ((3*4) + (2*(12^2))) which is a sum (Plus .). -- WBR, Max Vasin. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
[Haskell-cafe] Type classes
Hi! I'm currently experimenting with a bibliography generation tool for LaTeX. It will (if it will be finished) use BibTeX databases but bibliography styles will be written in Haskell. I want styles to be able to transform database entries into some style specific data type, so I define class DatabaseEntry e where entryLabel :: e - String formatEntry:: e - String compareEntries :: e - e - Ordering Then I define data Entry = forall a. (DatabaseEntry a) = Entry a instance DatabaseEntry Entry where entryLabel (Entry e) = entryLabel e formatEntry (Entry e) = formatEntry e How can I define compareEntries for this instance? -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Type classes
Geest, == Geest, G van den [EMAIL PROTECTED] writes: Geest, I suppose you want to define compareEntries like this: compareEntries (Entry x) (Entry y) = compareEntries x y Geest, An option is to just implement it the following way Geest, (Haskell98!): class DatabaseEntry e where entryLabel :: e - String formatEntry :: e - String compareEntries :: e - e - Ordering data Entry a = Entry a No. I don't want that. The database parsing function returns Map.Map String Entry but entries can of different types (and these type vary over styles). -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Type classes
Stefan == Stefan Holdermans [EMAIL PROTECTED] writes: Stefan Max, class DatabaseEntry e where entryLabel :: e - String formatEntry :: e - String compareEntries :: e - e - Ordering Then I define data Entry = forall a. (DatabaseEntry a) = Entry a instance DatabaseEntry Entry where entryLabel (Entry e) = entryLabel e formatEntry (Entry e) = formatEntry e How can I define compareEntries for this instance? Stefan In general: you can't. The field of the Entry constructor has Stefan a existentially quantified typed. Given two arbitrary values Stefan of type Entry, this type may be instantiated with a different Stefan type for each value, so you cannot easily compare the fields. Yes, this require something like multimethods in CLOS. Stefan If you extend the DatabaseEntry class such that it supplies a Stefan method that allows to produce some canonical representation Stefan for database entries suited for comparison, then you could Stefan take that road. Stefan Are you sure that your Entry type needs to be existentially Stefan quantified? I want a map of entries (mapping lables to entries). Generally each style can define its own data types for database objects. Converting entries from data BibEntry = { beLabel :: String , beKind :: String , beProperties :: Map.Map String String } is some sort of static type checking of the database. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Proper way to write this
Pupeno wrote: On Monday 26 December 2005 02:41, Donn Cave wrote: I don't think it will be too much worse. I would not try to combine the struct updates, in the both case -- it doesn't buy you anything, and pulls you into duplication you don't want. What about this runDaytimeServer :: DaytimeServer - IO DaytimeServer runDaytimeServer dts = do dts' - runStreamDaytimeServer dts dts' - runDgramDaytimeServer dts' return dts' runDaytimeServer dts = runStreamDaytimeServer dts = runDgramDaytimeServer Don't write a - foo return a write foo instead. -- WBR, Max Vasin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe