[Haskell-cafe] [Off-topic]Functional parsing theory
Hi, all, I've been working in a tool that reads a grammar with associated actions and act on input based on that grammar. I would like to rewrite it in a functional style, but I've not been able to find a theory that would handle any possible grammar with cyclicity and empty productions, and flexibility is more important for this tool than performance. Do you have a suggestion on that? What I'm using now is this (non-functional) article on Earley method: http://www.springerlink.com/content/602270808666074p Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: bitspeak 0.0.1
Sure, Huffman was actually my first tought. But I couldn't think of a pratical display for the result of Huffman encoding that could be easily followed by a human looking at the screen. Since it's an optimal code, letters would not be grouped in alphabetical order. There is a compromise. There is such a thing as an ORDERED Huffman code. Consider a set of strings. If they call begin with the same first letter, assume that letter and consider the suffixes instead. Otherwise, choose a letter L such that as close as possible to half of the strings begin with a letter preceding L in the alphabet as close as possible to half of the strings begin with the letter L or a later letter. I believe that's what I've done. I use this file to give weight to letters: http://bitbucket.org/mauricio/bitspeak/src/tip/src/Corpora.hs After each letter is selected I keep only sufixes after that letter, and then I use 'splitData' to find the point where I'll separate both halves: http://bitbucket.org/mauricio/bitspeak/src/tip/src/Main.hs Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: bitspeak 0.0.1
bitspeak is a small proof of concept application that allows writing text using only two commands (yes/no, 1/2, top/down etc.). There is a parallel between data compression algorithms and this sort of task, expressing a sentence in the minimal number of bits via compression also minimized the number of yes/no questions that need to be asked. In particular, a Huffman coding: Sure, Huffman was actually my first tought. But I couldn't think of a pratical display for the result of Huffman encoding that could be easily followed by a human looking at the screen. Since it's an optimal code, letters would not be grouped in alphabetical order. Thinking again, this could be easily accomplished... I could just list the alphabet and the next bit to be choosed below each letter. TODO for 0.1. Thanks! Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: bitspeak 0.0.1
bitspeak is a small proof of concept application that allows writing text using only two commands (yes/no, 1/2, top/down etc.). Looks cool! Did you forget any dependencies tho? I get the following error: Oops... Three modules ended up missing in .cabal file. Just uploaded 0.0.2 to hackage, it should work. Thanks! Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: bitspeak 0.0.1
Hi, all, bitspeak is a small proof of concept application that allows writing text using only two commands (yes/no, 1/2, top/down etc.). It is intended to show how people with disabilities similar to Stephen Hawking's (i.e., good cognitive hability, but very few movements) can write text. http://hackage.haskell.org/package/bitspeak http://bitbucket.org/mauricio/bitspeak/wiki/Home Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Embedded funcional programming?
Hi, all, I've beeing working with some people who do programming for wireless devices. 100% of their code uses C, and I would like to show them nice things they could do with funcional programming (not necessarily Haskell. I believe, say, Standard ML could be also very nice.) I'm new to this, so the only problems I see are finding a compiler that targets the platform (ARM7, for instance, or others) and uploading the compiled firmware to the device. Do you think this can be a straightforward path? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: GPL answers from the SFLC (WAS: Re: ANN: hakyll-0.1)
> To my knowledge, the LGPL only allows *linking* with non-(L)GPL > software. But GHC doesn't just link but performs massive > cross-module inlining. So in my opinion, LGPL is not a solution, > too. Use BSD3! But that massive cross-module inlining happens at your computer, where the rights allowed by GPL for private use applies. So, as long as you distribute the GPL/LGPL code separate from your BSD/proprietary code, no restrictions should apply. (I believe this applies even with GPL, as all you'll be using in your code is the API which, as far as I know, can't be copyrighted, like any kind of interface -- even hardware interface. But I can't find a source on that.) Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Using Haskell's FFI to send ancillary data over Unix domain sockets
> For me, this presents a few problems. I don't know where to get > the SCM_CREDENTIALS constant, I have no idea what flags to use > (does the Network module help with that?), I don't know how to > get from a list of file descriptors or a tuple to a Ptr, and > perhaps most importantly, I have no idea how to get the lengths > of pid_t, uid_t, gid_t, and socklen_t. The basic answer is that you can use tools like hsc2hs, c2hs or greencard. I also wrote this package that may be of help: http://hackage.haskell.org/package/bindings-posix You may want to look at the source code to see how to apply the idea to your needs. Note that this package uses a lot of macros I wrote myself (see package bindings-DSL), so you should not use them if you want to stick with standard tools. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: do we need types?
A type class is a relation between types. Yes, but not officially, just de facto: http://hackage.haskell.org/trac/haskell-prime/ticket/90 Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Hackage download statistis
Hi, all, Some time ago a download statistic of hackage was made available, and analysed in a few ways. Googling for it still find that at a Galois web page. I though that, since the tools to get that were there, this would be output once in a while, but it seems it hasn't been done since then. Does anyone know if there are plans about that? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Using Cabal during development
> Eventually, I think using cabal during development may be > convenient. The only drawback is that you have to specify each > dependency and -- above all -- every module each time you add > one. When writing bindings-posix, bindings-glib etc., which have lots of modules, I used a shell script to take all modules under ./src to .cabal. What it did was: 1) for each subdirectory, create a .hs file that reimport all modules under that subdirectory; 2) list all .hs (and, in my case, also .hsc) under ./src and insert then into .cabal. I've found that scripts of this kind have been very usefull. They require you to follow some rules (like, say, all modules with name mapping to directories are always a reimport of submodules). > Then, to compile you executable with ghc (because Cabal is > definitely not convient when you have a lib and an executable in > the same package): ghc --make --package-conf pkg.conf.d main.hs > > Again, should you have better/simpler ways to achieve this, I > would be glad to know them. I usually find useful, at first, to build only the executable and leave the library. When modules get stable enough, I separate both. Other scripts have been also usefull: one to check uncommited changes in all packages I'm working in, other to sync all my local packages with their repos. You could have a single 'b' script you could run like: b l # build and install your library in local database b t # build and run your test package executable b m # update module list in .cabal file for all your packages etc. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: GUI programming
> The problem is that the GUI code has become very ugly and I'm > tempted to rewrite it totally. I've been looking forward to the > FRP stuff, but I've never seen a single definition of the term. > Conal Eliot's "denotational programming" is too general to be > definition. I want to try Grapefruit, but I got totally lost > when I see arrow notation. This is not what you are looking for, but if you also want to check something extremely less powerfull but extremely more simple, you may consider this sugestion I made some time ago for a GUI library: http://article.gmane.org/gmane.comp.lang.haskell.cafe/66638 Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: C functional programming techniques?
>> Sorry if this looks weird, but do you know of experiences with >> functional programming, or "type programming", with C? > I would use a higher level language to emit valid C. Basically, > use a strongly typed macro language. "All" you will have to > prove is that your emitter produces type safe code, which you > can do by induction and is straight forward. This is interesting. I wasn't thinking at first about actual formal proofs, just some way to make small C posix-only programs easier to read an maintain by using a "big picture" functional look. But I would like to try that. Do you have some link to an example of such proof by induction of type safety? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] C functional programming techniques?
Hi, all, Sorry if this looks weird, but do you know of experiences with functional programming, or "type programming", with C? Using macro tricks or just good specifications? I know this is not absurd to a small extent. I've heard of proof tool certificated C code on the net (although I don't understand that theory), and I was also able to use what I learned from Haskell in a few C-like tasks. [*] So, I imagine if someone has done such kind of experiment seriously, like others have done with object-oriented programming (gobject etc.). Google told me nothing. Thanks, Maurício [*] This may actually be interesting. I had to use a proprietary script language mixing the worst of FORTRAN and C to drive an application, and I tried to use what I learned from Haskell by, say, prohibiting side effects out of some isolated code areas that got well specified input and gave well specified output -- even if the inside of the block itself was a huge mess. The result was actually fun to use, and after two years without looking at that code I was asked to adapt the application to be used inside another, which I could do in half a day! Maybe I should write a "Why functional programming matters - 2" on that :) It's easy to show FP is cool with abstract problems, but it's far more cool when we can show it can save even programmers with no CS theory background from huge headaches. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: bindings-DSL 1.0.4 (Category: FFI)
>> Here is my attempt. I added #callconv macro, that accepts >> a calling convention parameter. The lines below are now >> equivalent. > Builds fine here and looks reasonably fine. Okay. Package uploaded, documentation updated. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: bindings-DSL 1.0.4 (Category: FFI)
>> http://hackage.haskell.org/package/bindings-DSL >> http://bitbucket.org/mauricio/bindings-dsl > The only thing I've missed for now is a #ccall equivalence > for "stdcall" functions, I hacked one up myself and called it > #stdcall, but it would be nice to have in the package proper if > possible. Here is my attempt. I added #callconv macro, that accepts a calling convention parameter. The lines below are now equivalent. #ccall do_something , CString -> IO CInt #callconv do_something , ccall , CString -> IO CInt Would you mind give it some testing (and of course sugestions as you wish) before I upload it to Hackage? The link below gives you a few options for download format. Look for version 1.0.5. http://bitbucket.org/mauricio/bindings-dsl/downloads There are a few good C libraries that work well under Linux and Windows (libusb1.0 for Windows is in beta now, for instance). Do you think we should have a macro that defaults to 'ccall' in Linux and others and to 'stdcall' on Windows? If so, I would need some help to avoid portability issues (like a list of platforms and proper defaults). Thanks for your toughts, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: bindings-DSL 1.0.4 (Category: FFI)
Hi, bindings-DSL is a mature and well documented preprocessor domain specific language you can use to generate bindings to a C API. It's based on functionality provided by hsc2hs. These are links to Hackage page and documentation: http://hackage.haskell.org/package/bindings-DSL http://bitbucket.org/mauricio/bindings-dsl New in this version: * Support for C unions. * Use of macros for wider portability. An example on the use of unions follow. Suppose you have: union example { int k; char c[4]; }; Then, using bindings-DSL, you'll write: #starttype union example #union_field k , CInt #union_array_field c , CChar #stoptype Here is a ghci session showing the resulting code: > let value = C'example 1 [] > u'example'k value (2^10) C'example {c'example'k = 1024, c'example'c = [0,4,0,0]} > u'example'c value [1,0,0,0] C'example {c'example'k = 1, c'example'c = [1,0,0,0]} > u'example'c value [0,0,0,1] C'example {c'example'k = 16777216, c'example'c = [0,0,0,1]} Peeking an uninitialized memory address: > v <- alloca $ \p -> peek p :: IO C'example > v C'example {c'example'k = 81842189, c'example'c = [13,-48,-32,4]} Hope it's useful to you. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: changelogs for packages on Hackage
Some packages have a changelog file in them that we could display, though most don't. Debian policy requires changelogs of standard format. Most packages use a well known version control system (darcs, mercurial etc.). Cabal also has fields helping identifying where in vcs history are each version placed. Listing change history between them is something we can script. Personally I think, though, that changelog format should be part of Cabal package format documentation. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: consulting and contracting
>> I was wondering how many haskell consultants and contractors >> (ie. freelance programmers) there are and how much demand there >> is for their work. > > I've done three Haskell contracts last year and this year, all > in the financial industry in the New York area. Two of them were > for the same client, developing a couple of modeling systems for > products like swaps and bonds, and the other was an upgrade of > an existing Haskell trading-related system. Do you guys know this? http://www.rentacoder.com I wonder if hackage 2.0 could be made into such a thing for Haskell developers :) Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Checking dependencies from C packages in cabal
> Until you get the perfect answer you may want to have a look at > the cabal definitions of > > zlib digest OpenGLRaw GLUT readline GLFW wxcore terminfo > berkeleydb BerkeleyDB hubris pcre-light HDBC-mysql HDBC-sqlite3 > HDBC-odbc HDBC-postgresql I do know them. But they just include needed .h and .c files with Haskell package, mark required libraries but do no version check, or delegate the task to configure scripts or external programs. HDBC-mysql Setup program gave me a start, thought. Thanks. > Also make sure to search the Cabal mailinglist and maybe even > move this thread to the Cabal mailinglist. Cabal page sugests Haskell libraries mailing list for questions. I should have used that. Thanks. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Checking dependencies from C packages in cabal
Hi, all, When pkg-config info is not available for a library (when I could use pkgconfig-depends), what should I use to check if needed libraries are installed and to give the compiler all needed info about include files and library location? Also, is it possible to do that without configure and make files? I have no experience with them. I also tried reading the Distribution module, but wasn't able to recognize what could be a natural way to handle this problem. Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: binding to C libraries on Windoww
> To reply to an earlier point of Andrew's (I can't find the quote > now, sorry), one of the biggest difficulties developers face > on Windows is the lack of common install locations/practices. > Windows software is usually distributed as a binary, which may > or may not include header files. These files may be installed > in any of numerous locations, such as C:\Program Files\, the > user's home directory, the system directory, or directly off the > drive root. Defaults are not common among different programs or > even versions of programs, and install locations are frequently > changed by users anyway. Libraries and headers are usually > not located on the PATH environment variable, and there's no > standard INCDIR or LIBDIR variable either. If Windows lacks a sane environment, why not to provide one? I don't know how much of it mingw already provides. If it doesn't, that would be a nice Haskell project :) It could be called Windows SaneEnvironment, and include a few basic policies for packages and a package manager. When I needed Windows myself I would certainly help maintaining. It would not be hard to find others who still will. Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Do you need Windows USB in Haskell?
> I don't need usb and I can't say I'm a windows user, but I'd > be glad to test it since I have it on a virtual machine. In my > case, installation fails on "bindings-common". bindings-common fails on windows due to an old version of C library with GHC's windows version of gcc. Current version of bindings-libusb uses bindings-DSL. I'm glad that you offered to help. But usb is not supposed to work on windows yet. The windows version of the C library has been worked on recently, so, I would need someone who would follow closely this still alpha code and maybe even sugesting adaptations to libusb-1.x build system if necessary. I don't think it's fair to expect that from someone who isn't going to use the library. Thanks! Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: binding to C libraries on Windoww
> I guess there's a difference in culture here. > > On Unix, it is usual to distribute programs as source, and build > from source. I see more than a cultural issue here. Suppose you write bindings to somelib-1.0.2, and release it with somelib-1.0.2. Then, somelib-1.0.3 is released to solve a serious security issue with 1.0.2. Linux or unix distributions will update their repositories, but users of your bindings will blindly keep using 1.0.2. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Binding to C in Windows (was: Low Level Audio - Writing bytes to the sound card?)
> Unfortunately, I've yet to find a single Haskell package that > binds to C which will actually compile on Windows. :-( Do you know how can we check dependencies to C libraries in Windows? Is pkg-config available? What about packages with no pkg-config configuration? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Do you need Windows USB in Haskell?
Hi, I keep this direct binding to libusb-1.0.x: http://hackage.haskell.org/package/bindings-libusb on top of which Bas maintains a nice USB library: http://hackage.haskell.org/package/usb Work has been done to support libusb-1.0.x in Windows. So, as long as my bindings-libusb works properly with that, Bas' as well as any other library based on it will work too. Problem is: I don't have a Windows machine where I could test this. So, if you need USB in windows, please keep in touch. I wouldn't ask you to write any code, but I need to know what builds and what doesn't. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: I miss OO
> Python: > note1.time() > cursor1.time() > staff1.time() > > (...) > > So I'm thinking of moving to a scheme in Haskell using modules, > most types being defined in their own modules, and doing > qualified imports. Generic names like 'time' can be defined in > each module w/o clashing. > > (...) > > I would be interested in comments... is this a good way to do > things? Am I trying too hard to impose OO on Haskell and is > there a better way? I had this same experience. After you learn how to think in Haskell, the problem will just disapear. Maybe it would help you more if, instead of just this small detail, you write the general idea of what you want your application to do. Then we could sugest you a Haskell-like design where you would not need note1.time, cursor.time etc. In time you'll probably want to study this: http://hackage.haskell.org/package/haskore Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell Weekly News: Issue 140 - November 22, 2009
> Incidentally, I've always wondered about the politically correct > way of referring to this programming language (and related > implementation in the above-mentioned type system) in academic > circles; Is this a question of politically correctness? Since there's no discrimination or prejudice involved, I think it's more of a question of social rules. If you are using a word where it's going to be indexed, like article titles, I vote for beeing accurate. But outside that, it's difficult to answer this in a way that extends beyond one's own circle of friends. Censoring a bad word may be polite for some, and offensive for others, what could we do about that? Regarding brainfuck itself, I think beeing censored is part of the joke. > In general, if a programming language-related term contains what > is generally regarded as a profane word as a component, for > what kinds of written material should I prioritize accuracy vs. > propriety? If we decide to allow * inside conids and varids in Haskell, and have a rule that names clash when they differ only by a letter replaced by a *, we have gone too far. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How does cabal determine version ranges in the dependencies?
If it doesn't break dependencies, it won't be called http 4001, it will be called 4000.0.9 :) Check: http://www.haskell.org/haskellwiki/Package_versioning_policy I see. Thanks for the link. I wasn't aware of the versioning policy. Just to clarify though, wouldn't the next higher major version by 4000.1 rather than 4001? Hmm... I think so. Conformance to these policies are rather new, I believe. I have to say I didn't know about PVP a few weeks ago, when an user of a package I maintain sugested me to follow it. Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Idea for a very simple GUI llibrary
Thinking of a parallel with Java for a second, is there a GUI library out there that's structured like Java Swing? Meaning, there is a GUI library that has a small platform-specific GUI foundation (e.g. a per platform implementation of the core AWT functionality) and the rest of the functionality is pure haskell? I believe the plan I sugested in the begining of the thread could be easily made into what you want. It could not be, however, as powerfull as the mainstream libraries. Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: How does cabal determine version ranges in the dependencies?
> I recently started porting cabal-install to Freebsd. When > I looked at its dependencies on hackage, I noticed HTTP > (>=4000.0.2 && <4001). However the latest HTTP version on > hackage is 4000.0.8. That struck me as kinda odd. How can cabal > tell that it won't be compatible with HTTP version 4001? If it doesn't break dependencies, it won't be called http 4001, it will be called 4000.0.9 :) Check: http://www.haskell.org/haskellwiki/Package_versioning_policy Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Idea for a very simple GUI llibrary
> Nice idea. I will try it if you write runGUI :-) Sure, just let me know :) If this is to be done, I think it's better that the person writing the Haskell code do not write runGUI, so the implementation details wouln't discourage ideas that make life easier for users. > This is an imperative style library. For more Haskellian GUI > library ideas, see Fruit (http://www.haskell.org/fruit/) and TVs > (http://www.haskell.org/haskellwiki/TV). They may not pass the > "builds" constraint :-P I do remember looking at TVs and also Fudgets as sugested by Keith. But there's a unfilled hole for a library that's conceptually simple. I believe that with the library I described users (begginers in Haskell?) could even use QuickCheck and HUnit with their GUI code. Thanks for your comments, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Idea for a very simple GUI llibrary
Hi, Here is a sketch for a library with these properties: -> Easy to test. All Haskell code can be tested in a text terminal. Also, testing code that uses the library can also be done without using a GUI. -> Extremely easy to document and use. -> Not even close to Gtk2hs power, but enough for small applications. -> Could be the first GUI to build on hackage :) What we need is: -> MyState. A user suplied type for application state. -> WidId. A user suplied type for widget identifiers. -> Gui wi. A type capable of describing an interface with all of its state. It's an instance of Eq. -> Event wi. A type for events. -> Prop. A type for properties than can related to a WidId. Running an application would be like this: main = runGUI initState -- An initial MyState. event -- :: MyState -> DiffTime -> Event WidId -> MyState props -- :: WidId -> [Prop] action -- :: MyState -> DiffTime -> IO (Maybe (MyState,Gui WidId)) timeout-- :: DiffTime DiffTime parameters for callbacks are always the time elapsed since application started. From initState and event, the implementation of runGUI can save a state that optionally changes with time. From props, it can get details on what to present in widgets associated with a WidId (selected state, picture to draw etc.). action presents a chance for using IO, and optionally change state and GUI description. timeout is the maximum time runGUI implementation is allowed to wait between calls to action. Examples for those types: newtype MyState = { lastUpdate :: DiffTime, builtGui :: Bool, earthCoordinates :: (Double,Double), map :: SVG, ... } data WidId = XCoord | YCoord | MapWindow | ReloadButton ... data Gui widid = TitleWindow (Gui widid) | Tabs [(String,Gui widid)] | PressButton String widid | Selection [String] widid | ... deriving Eq {- Eq is needed by runGUI to detect if GUI has changed after the last call to action. -} data Event widid = ButtonPressed widid | FileSelected String widid | OptionSelected String widid | ... data Prop widid = Active Bool | Text String | Draw SVG | ... I believe this can represent most kinds of simple applications, and be efficient enough for practical use. It's interesting that all of this can be designed, implemented and tested independent of runGUI implementation. Actually, if you want a pet project and want to write and design the Haskell part, I may probably be able to write runGUI for you :) Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: bindings-SDL 1.0.2, the domain specific language for FFI description
> I had two structs, one of which used the other as a field type. > I was using the generated identifier of the first as the type > for the second, so it had the form c'STRUCT_NAME. So the field > macro looked like this: > > #field foo , c'STRUCT_NAME > > It did not like this, complaining about the single quote. > > I have since noticed the notation in the > documentation. Perhaps the actual bug is that this notation was > not pointed out in prose? I believe I forgot to write a section with that information, as well as others one would like to know from start. I wrote a new section trying to fix that in 'how to use it' topic. http://bitbucket.org/mauricio/bindings-dsl/wiki/HowToUseIt I'm not sure I have already got to a point where documentation is clear and complete enough but not too long and boring. If you also thing some parts of documentation were not helpful, or if more is missing, please let me know. Thanks for your feedback. Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: bindings-SDL 1.0.2, the domain specific language for FFI description
> I did not notice when this was released, but I saw it on Hackage > yesterday and, with it, wrote some of the easiest bindings to a > fairly complex C API I've written in a while. This package is > excellent! Thank you for sharing it. Thanks. My hope is that it saves as much time from users as the support from this community saved for me. > My only complaint is that the macros get confused if you use a > Haskell type that has a single quote in it. Can you give me an example? Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: bindings-SDL 1.0.2, the domain specific language for FFI description
Hi, This package is to be used with hsc2hs. (hsc2hs is called automatically if you use Cabal.) It's a self-contained set of macros used to create a Haskell wrap for a C interface. They follow the idea that it's better to have a C-like wrap code first and then write Haskell-like code on top of that than going directly from C to Haskell style. Hackage link: http://hackage.haskell.org/package/bindings-DSL Wiki documentation: http://bitbucket.org/mauricio/bindings-dsl The fancy 'domain specific language' comes from 'binding-SDL' macros hability to describe a C interface. Instead of writing Haskell or preprocessor code, you can use 'bindings-DSL' macros to describe the interface you want to wrap without knowledge of how that description translates to preprocessor or Haskell code. Suppose, for instance, you have the following C struct: struct example_struct{ int n; struct example_struct *p; } It will be described like this: #starttype struct example_struct #field n , CInt #field p , Ptr #stoptype and this gives you a Haskell data type (automatically named C'example_struct) with the same fields and Storable instantiation. Here is a bigger example, with structs, macros, functions and global variables. Suppose you want to wrap this: http://git.savannah.gnu.org/cgit/gsl.git/tree/multimin/gsl_multimin.h Then this is how your 'bindings-DSL' code will look like: http://bitbucket.org/mauricio/bindings-gsl/src/tip/src/Bindings/Gsl/MultidimensionalMinimization.hsc That code translates to these Haskell declarations: http://hackage.haskell.org/packages/archive/bindings-gsl/0.1.1.6/doc/html/Bindings-Gsl-MultidimensionalMinimization.html 'bindings-DSL' came from previous 'bindings-common' package. It started as an effort to have many Haskell interfaces to good libraries available on Hackage, and came to be a language to support writing such interfaces easily and reliably. Hope it's usefull to you. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How much time until dependencies are rebuilt in hackage?
Suppose package B depends on A. If a new version of A is uploaded to hackage, how much later package B will be rebuilt (either to show a problem with the new version or to solve a problem with a previous version of A)? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Weird dependency failure log
>> > Header files are associated with a library. >> > If there is no library then nothing gets >> > registered. This is by design. >> > If it's not a library, nothing can depend on >> > it. >> But please tell me then where my package fits. > I'm not sure I understand the question. Can you > clarify what you mean. Well, you said that if it's not a library, it can't have dependencies, and my package is not a library and does have dependencies. Maybe it should not be a package at all, but then I would not know a safe way to distribute it without breaking packages when something changes. I inserted a dummy module so that the package is accepted as a dependency. But I'm not sure this is appropriate. Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Weird dependency failure log
>>> This is a package with no library and no executables. That's >>> not supposed to work. >> Why shouldn't this be supposed to work? It does install needed >> files (two include files for hsc2hs), and they do stand for >> themselves to justify a package of its own. > Header files are associated with a library. If there is no > library then nothing gets registered. This is by design. Doesn't Cabal option 'install-includes' contradicts that? > If it's not a library, nothing can depend on it. But please tell me then where my package fits. Many libraries I wrote and use depend heavily on it. Versioning in this package is extremely important, as a change in design for any macro would change all names in depending libraries. Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Could someone teach me why we use Data.Monoid?
I have looked the concept of monoid and something related, but still, I do not know why we use it? I don't know if it's a good example, but it's simple. This package I wrote uses reverse polish notation to write gtk2hs layout windows. http://hackage.haskell.org/package/gtk2hs-rpn Since the type for operators used in the stack is a Monoid instance, you can combine many of them to create new operators. I believe you can think of monoids as things you can sequence to make new ones of the same type, but someone with better knowledge please say if this is actually a misleading idea. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Weird dependency failure log
There's one thing special about bindings-DSL. It's a package with a set of macros for hsc2hs, and contains no Haskell code. Maybe this revealed some hidden error in package dependency checking. This is a package with no library and no executables. That's not supposed to work. It contains hsc2hs data all dependent packages use. Why shouldn't this be supposed to work? It does install needed files (two include files for hsc2hs), and they do stand for themselves to justify a package of its own. And other packages could also want to distribute just data. Say, a database of daytime saving dates to be used by a clock package. Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Weird dependency failure log
Hi, all, Hackage shows a log failure for 'bindings-gsl': Configuring bindings-gsl-0.1.1... cabal-setup: At least the following dependencies are missing: bindings-DSL ==1.0.* But here is, at version 1.0.1, no building problems: http://hackage.haskell.org/package/bindings-DSL There's one thing special about bindings-DSL. It's a package with a set of macros for hsc2hs, and contains no Haskell code. Maybe this revealed some hidden error in package dependency checking. Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Sending patches to ghc related repositories
Hi, all, I just tried to send a patch to a ghc tool. I see in hackage that the maintainer e-mail is 'cvs-fpto...@haskell.org' (package is hsc2hs). I tried sending darcs patch to this e-mail, but it's refused as it's not on that server allowed e-mails table. The patch isn't really important, just a documentation typo, but I'm curious about what is the proper way to do it. Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Nice addition to Foreign: castAny
castAny :: (Storable a, Storable b) => a -> b castAny = unsafePerformIO . genericCast where genericCast :: (Storable a, Storable b) => a -> IO b genericCast v = return undefined >>= \r -> allocaBytes (max (sizeOf v) (sizeOf r)) $ \p -> poke p v >> if False then return r else peek (castPtr p) > let a = -1000 :: Int16 > castAny a :: Word16 --> 64536 > castAny a :: Ptr () 0xb4c2fc18 Try it on a big endian architecture, or one that has alignment restrictions, or a different size for HsChar or so forth. Casting by 'punning' (as the C folks like to call it) does have uses, but they are generally hardware dependent and useful only in certain rare circumstances that a generic cast probably isn't likely to fill. Do you think this could be used as a way to handle C unions? If I had something like union example { struct firstview { char c; int n; } fv; long double ld; }; and 'firstview' had been mapped in Haskell as, say, FirstView {firstViewC :: CChar, firstVewN :: CInt} I could check what I would get after pokeing values using: (firstViewN . unionCast) (pi :: CDouble) Note that I changed the name from castAny to unionCast to reflect its use. Thanks for your comments, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Marshalling arrays without flakiness? (poke example)
>> I would like to know whether there is a good way to marshal the >> following structure to C without using pointer arithmetic done >> by a programmer (as opposed to a tool). Here is an example with poke. It's completely useless, except for demonstration :) You have a global variable in C that receives data in a struct, and a 'print' function that prints it. *** C header: *** #define NPOWERS 6 typedef struct { double number; double negpowers[NPOWERS]; } power_struct; extern power_struct np; void print_np (void); *** C definition: *** power_struct np; void print_np (void) { int i; printf("\n"); printf ("Negative powers of %g: \n",np.number); for (i=0;i<=NPOWERS;i++) printf(" %g",np.negpowers[i]); printf("\n"); } *** Binding module, with hsc2hs macros: *** #starttype power_struct #field number , CDouble #array_field negpowers , CDouble #stoptype #globalvar np , #ccall print_np , IO () *** Haskell calls: *** main = (flip mapM_) [2..5] $ \n -> poke p'np (C'power_struct { c'power_struct'number = n, c'power_struct'negpowers = iterate (/n) (1/n) }) >> c'print_np *** Output *** Negative powers of 2: 0.5 0.25 0.125 0.0625 0.03125 0.015625 0 Negative powers of 3: 0.33 0.11 0.037037 0.0123457 0.00411523 0.00137174 0 Negative powers of 4: 0.25 0.0625 0.015625 0.00390625 0.000976562 0.000244141 0 Negative powers of 5: 0.2 0.04 0.008 0.0016 0.00032 6.4e-05 0 Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Marshalling arrays without flakiness?
I would like to know whether there is a good way to marshal the following structure to C without using pointer arithmetic done by a programmer (as opposed to a tool). typedef struct{ double a[10]; double b[10]; double b[10]; } foo; With my my 'bindings-common' package it's done like this: #starttype struct foo #array_field a , CDouble #array_field b , CDouble #array_field c , CDouble #stoptype There's no problem if you change the order of the fields, or ommit one of them. To be consistent with Marshal.Array, Haskell datatype fields corresponding to a, b and c will be lists. If you try to poke some value with list fields containing more than 10 elements, only the first 10 will be stored. That size is detected automatically. If you want to check how does the code you write compare to the Haskell code you get, you can check this binding to posix : http://bitbucket.org/mauricio/bindings-posix/src/tip/src/Bindings/Posix/Sys/Utsname.hsc http://hackage.haskell.org/packages/archive/bindings-posix/1.2/doc/html/Bindings-Posix-Sys-Utsname.html Based on this example, this is how you would write code to tell you the name of your OS. (This is a 'peek' example, but 'poke' code would be similar.) name :: IO String name = alloca $ \ptr -> do c'uname ptr uts <- peek ptr let original = takeWhile (/= 0) $ c'utsname'sysname uts return $ map (toEnum . fromEnum) original Here is some documentation on that package: http://bitbucket.org/mauricio/bindings-common/wiki/Home Hope this helps. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] C headers in cabal dependencies
Hi, I've been using 'install-includes' in a package. I sometimes make small changes to those include files, and I've seen that cabal doesn't consider then dependencies, i.e., doesn't rebuild .hsc files depending on then. I'm not sure if this is an error, as parsing hsc2hs input may not be cabal task. Anyway, I would like to suggest that files in install-includes be considered dependencies and that files under 'includes' be also included when processing '.hsc' files. Thanks. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Nice addition to Foreign: castAny
This could be beside castPtr, castCharToCChar etc. castAny :: (Storable a, Storable b) => a -> b castAny = unsafePerformIO . genericCast where genericCast :: (Storable a, Storable b) => a -> IO b genericCast v = return undefined >>= \r -> allocaBytes (max (sizeOf v) (sizeOf r)) $ \p -> poke p v >> if False then return r else peek (castPtr p) GHCi: > let a = -1000 :: Int16 > castAny a :: Word16 --> 64536 > castAny a :: Ptr () 0xb4c2fc18 > castAny (castAny a :: Ptr ()) :: Int16 -1000 > let b = pi :: CLDouble > b 3.141592653589793 > castAny b :: CInt 1413754136 > castAny b :: Ptr () 0x54442d18 > castAny b :: CFloat 3.3702806e12 > castAny b :: Int8 24 At minimum, this is safer than 'unsafeCoerce'. What do you think? Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Word128, Word256
To have it defined is one thing. To actually implement i128 and i256 is quite another thing. Are you willing to actually do all of the work necessary to implement the unboxed i128 code? Dream away! John Meacham also told me that even if I get there, it wouldn't do what I want (use it to support complex numbers). Can you tell me what are the issues involved? From my naive view, something like CDComplex (mapping to C double _Complex) wouldn't be different than what's done for other basic types. Why am I wrong? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: CComplex in jhc (was: Word128, Word256)
>>> Something like 'CComplex CDouble' has been proposed before... >> 2) Since all (few) answers were favorable, should I ask for a >> ticket to be created? How? > Well, before trying to get it standardized, you need to get it > implemented and tested by at least one compiler to explore the > design space and tradeoffs. I would happily accept any patches > into jhc that a support for such types, I don't even think it > would be that difficult to do. One should say jhc code is really clear. It's the first compiler code I try to read and for a moment I actually believed I could write the patch :) Below is my completely naive attempt. If you want to tell me where to go from here, I'll try. (For instance: how do I get 'rt_bits_double_complex_' to exist.) However, I think this is far beyond my skills... Thanks for your thoughts, Maurício hunk ./src/DataConstructors.hs 927 -(tc_World__, "void") +(tc_World__, "void"), + +(tc_CFComplex, "float complex"), +(tc_CDComplex, "double complex"), +(tc_CLDComplex, "long double complex") hunk ./src/data/names.txt 21 + +CFComplex Foreign.C.Types.CFComplex +CDComplex Foreign.C.Types.CDComplex +CLDComplex Foreign.C.Types.CLDComplex + hunk ./src/data/primitives.txt 24 -#Jhc.Float.Float, fbits, float, FLT_MAX, FLT_MIN -#Jhc.Float.Double, fbits, float, DBL_MAX, DBL_MIN +Jhc.Float.Float, fbits, float, FLT_MAX, FLT_MIN +Jhc.Float.Double, fbits, float, DBL_MAX, DBL_MIN hunk ./src/data/primitives.txt 43 +Foreign.C.Types.CFComplex, ubits, float, 0, 0 +Foreign.C.Types.CDComplex, ubits, float, 0, 0 +Foreign.C.Types.CLDComplex, ubits, float, 0, 0 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: A 3 line program --> Reid, Don, Daniel
Philippos, Doesn't the line below means everything to be interpreted will be considered as latin1? \usepackage[latin1]{inputenc} Unicode as UTF-8 won't fit here. I would sugest transfering the problem to latex. Why not to print 'fa\c cade' instead of 'façade'? It's 7 bits and will never fail. Best, Maurício Thank you for your help. I am sure that you are right as to the cause of the problem. However, I do not know what I should do to solve it. The Haskell program is generated by LaTeX macros. (...) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Word128, Word256
Something like 'CComplex CDouble' has been proposed before... I know, I started most of the discussions :) The wiki says before asking for a ticket I should try to talk about it in the mailing list. My attempts never got much attention, but all replies gave favorable answers. Last week, though, I posted about it in haskell-prime and got no answers. I'm not sure what to do. Which would be the best option? 1) Since it's not important for enough people to make a big discussion, should I leave this for the future, maybe when Haskell become the language of choice for numerical work? Okay for me, as I sincerely believe this won't take much :) 2) Since all (few) answers were favorable, should I ask for a ticket to be created? How? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Word128, Word256
Hi, Do you think we could have the range of sizes for Int* and Word* expanded to allow also 128 and 256 bits sizes? My reason is that I have a long standing issue trying to bind to C numerical libraries using complex numbers, as those are usually structs passed by value. See this from GNU GSL: typedef struct { double dat[2]; } gsl_complex; I imagine I could do: type GslComplex = Word128 -- size would depend on architecture and then write foreign declarations to have: get_real :: GslComplex -> CDouble get_imag :: GslComplex -> CDouble gsl_complex_sin :: GslComplex -> GslComplex gsl_complex_cos :: GslComplex -> GslComplex Do you think this is a reasonable request? Thanks for your attention, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: pretty printing with comments
�typeURL= String Maybe the difference is the missing space between "type" and "URL". Ah, of course, I see it now, thanks! It ocurred to me that you could catch these kind of errors faster if haskell-src-exts included a basic program to pretty print a Haskell module that we could use out of the box. What do you think? Should it better be a separate package? Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: Reverse Dependencies in Hackage (demo)
> You can sort the tables of reverse dependencies by clicking on > the column headers. I wouldn't have thought about clicking in the columns headers. Maybe you could show the order arrow already in the beggining, before any clicks, this would give a hint. > - Rev. deps overview for all packages; is it useful? Sure! Do you think it could be complemented with a graph view? I liked this, from graphviz page: http://graphviz.org/Gallery/undirected/softmaint.html > - Is this the best way to present the information? Just cosmetics: in the individual package rev. dependencies, what do you think of using two columns, one for direct dependencies table and other for indirect dependencies? This would remove the need for navigation links in the main table. Also, here, if it's feasible, I think a graph with just the central package and 1fst and 2nd order dependencies could be usefull. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: [Haskell] ANNOUNCE: usb-0.1
>>> At least the following packages suffer from this problem: >>> bindings-common bindings-libusb bindings-posix > Most .tar files contain entries for the directories that > precede the entries for the files. This is only by convention > however. It looks like this tar file has an entry for > "src/Bindings/SomeFile.hs" without any preceding entries for > "src/AnotherFile" or for the directory itself "src/Bindings/". Thanks for the tip. I used Mercurial archive to create those tars: hg archive -t tgz -p 'bindings-common-1.1' ~/bindings-common-1.1.tar.gz I'll check if this is known in Mercurial, specially the weird output got from 7zip. Meanwhile, I'll be uploading as soon as possible new versions of those packages with runhaskell Setup.hs sdist Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Doing people's homework?
If you do a student's homework, you are cheating that student out of an education. Personally, I tend to find "exercises" without access to the answers a poor way to learn. You'll learn more from a well crafted example than you ever will by struggling at something yourself. In these lines, the homework policy could be extended to contain great solutions to all typical homework tasks. Teachers could build on that by instructing students to study and use such solutions to solve other tasks. Bonus could be given to students who could find even better solutions than those in the page, maybe with exponencial prizes like Knuth's checks :) Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Doing people's homework?
> I'm not really hip to the culture here so this is just an > observation, but some of the recent questions posted to this > list (and beginn...@haskell.org) look a lot like someone's > homework. Well, if homework "looks like" homework, the teacher is guilty of cheating. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: help with FFI
typedef struct { int *a; int *b; /*lots of stuff ... */ int *z; } foo; int create_foo(foo *f,FILE *file,int x,int y); int use_foo(foo *f,int w); int destroy_foo(foo *f); newtype Foo = Foo () foreign import ccall "static foo.h create_foo" c_create_foo :: Ptr (Foo) -> Ptr (CFile) -> CInt -> CInt -> IO CInt foreign import ccall "static foo.h use_foo" c_use_foo :: Ptr (Foo) -> CInt -> IO CInt foreign import ccall "static foo.h destroy_foo" c_destroy_foo :: Ptr (Foo) -> IO CInt Your 'create_foo' is only an initialization function, i.e., it initializes data in a Foo but do not allocate memory for the data such pointer points to. So, what you would like to do is something like this: import Foreign.Marshall.Alloc (...) ptrFoo <- malloc c_create_foo ptrFoo ptrCFile (...) (...) free ptrFoo Looking at malloc you see: malloc :: Storable a => IO (Ptr a) and this gives you the hint: you need to make an instance of Storable class with your Foo type. Storable method 'sizeOf' should provide the proper size to be used in such kind of memory allocation. (After that, you would probably want to learn about ForeignPtr, which would call, say, free and c_destroy_foo when your pointer is not beeing used anymore.) Best, Maurício P.S.: (Warning: spam promoting my own work.) If you use my package bindings-common, available in hackage, you can get that type and instance in a .hsc file by doing this: #bindings_starttype struct foo #bindings_stoptype _ But this package is not very popular yet, so I can't guarantee it's bug free. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANNOUNCE: A Levenberg-Marquardt implementation
Yes. It works this way. Tested in debian and old fedora Thank you for testing. I have just released bindings-levmar-0.1.0.1 on hackage. It simply replaces pkgconfig-depends with extra-libraries. I hope this solves the installation problems. Debian maintainer was willing to add pkg-config to lapack package: http://lists.alioth.debian.org/pipermail/pkg-scicomp-devel/2009-September/004508.html However, he and also Tollef (pkg-config maintainer) believe it's a better idea to add it to upstream package: http://article.gmane.org/gmane.comp.package-management.pkg-config/346 Unless you think that extra-libraries is a good long term solution, I'll still investigate on how to add pkg-config generation to configuration scripts and try to send a sugestion with a patch to maintainers of libraries wrapped in bindings-*. Although I don't know exactly how that patch should exactly be... Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANNOUNCE: A Levenberg-Marquardt implementation
>> Unless you think that extra-libraries is a good long term >> solution, I'll still investigate on how to add pkg-config >> generation to configuration scripts and try to send a sugestion >> with a patch to maintainers of libraries wrapped in bindings-*. > It is not practical to use pkg-config for such libraries. After > you persuade the reference code[1] of lapack to use pkg-config, > are you going to make ATLAS[2] do it also? And what about > Intel's mkl[3]? Or even lapack bindings provided by Nvidia's > CUDA[4]? Sure. But only for packages we have direct Haskell bindings to. You only need pkg-config available for the libraries you directly need for a cabal package. For complicated dependencies, just rely on your OS distribution (or Haskell Platform etc.). > I know it's hard to include every possibilities. But I prefer > some configuration switch that I can tune when building the > library. The idea is just to provide a default, working configuration. Anyway, I imagine this tunning should be done in a way that is transparent to a cabal package. > That's been said, it is still your package. And people can > always change the build scripts for their own needs. Not actually! I didn't work on bindings-levmar. I'm just the guy who started the idea of having low level bindings packages as basis for higher level bindings (so that this kind of problem can be solved at the same time for many, say, levmar high level bindings). That's why I would like to help acchieving good general guides for easy building. Wrapping of levmar is entirely van Dijk brothers' work. http://hackage.haskell.org/package/bindings-common Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANNOUNCE: A Levenberg-Marquardt implementation
> The C library prints error messages to stderr. (...) > Attached is the patch to the C levmar library. Thanks for the file. > The license issue is indeed a problem. Either your (linked + > distributed) code must be GPL or you must acquire a different > (commercial) license from the author of the C library. I don't think the GPL is itself a problem, I just meant that by packaging levmar with your bindings-levmar you probably have to GPL bindings-levmar itself. Although, since you used BSD, I don't think anyone will waste time bothering you about that. > Lapack has to be installed on the hackage server in order for > the package to build. Another option is to temporarily remove > the dependency on lapack from the cabal file. (...). But the > downside is that someone won't be able to cabal install it > without first modifying the .cabal file. That is unacceptable in > my opinion. Yes, this is difficult to solve... I've even asked that some nice, trusted C libraries could be installed on hackage so that we could bind to them. Maybe this can be accepted in the future if the idea of having many good quality bindings-* packages grow up. In the mean time, we have a two-sided problem: if we release a package with linking options removed we have to edit cabal file, which is unacceptable in my opinion too; and if we do not, all bindings-*, as well as all packages built on them, will be marked with "Build failure" on hackage and lack documentation, which is also unnaceptable... The good thing is that this problem can be isolated on bindings-* packages. If it is solved, it is solved once and for all. So far, my solution has been this: * to leave a 'pkg-config' line in bindings-* cabal file. This way, your package can be used properly as long as your installed library has pkg-config configuration, and this is easy to add (even for your favorite distribution library package) if it doesn't. * to comment that pkg-config line, so that hackage will build your package. Users can just add something like 'pkgconfig-depends: levmar' to their own packages. Though I have no reason to claim this is the best solution. Also: bindings-common has some macros that could easy your job. You could have used, for instance: #bindings_frac LM_INIT_MU #bindings_frac LM_STOP_THRESH #bindings_frac LM_DIFF_DELTA Although this would add a dependency, so I don't know if it's worth. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANNOUNCE: A Levenberg-Marquardt implementation
> Our binding consists of three packages: > > * http://hackage.haskell.org/package/bindings-levmar-0.1 Which were the changes you needed to do to the library code? I believe this is going to cause you two problems: maintenance (as you can't always be sure the patched version didn't introduce a bug) and license (as levmar is GPL. You can't distribute it linked to non GPL code). > * http://hackage.haskell.org/package/levmar-0.1 Cool. Don't you think the type level natural numbers deserve their own package? > Unfortunately the documentation of these libraries is not > available from hackage because bindings-levmar won't configure > because of a missing dependency (lapack) on the hackage server. I'll try to write you a patch to solve that after I study better your code. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ForeignFunPtr
Isn't freeHaskellFunPtr a required finalization procedure? Maurício the purpose of ForeignPtr is to attach a finalization procedure to the object behind the pointer. for example, you can have close called aimplicitly whenever the garbage collector finds you don't need a file handle any more. function pointers do not need finalization. We have ForeignPtr. Why isn't there a corresponding ForeignFunPtr? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ForeignFunPtr
Hi, We have ForeignPtr. Why isn't there a corresponding ForeignFunPtr? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Linking problem with GHCi
With a specific package (bindings-common, with the latest version in hackage) if I ask GHCi to read it I get: ghc-6.8.2: /home/mauricio/lib/bindings-common-0.2.5/ghc-6.8.2/HSbindings-common-0.2.5.o: unknown symbol `atexit' If I build a library or executable cabal package depending on it, I have no problems. Also, if I remove that 'atexit' wrap from 'bindings-common' I don't get this ghci error message anymore. This is actually not specific to that package. Attached is a darcs patch to a package where the only exported module contains just a wrapped 'atexit'. Thanks, Maurício Mon Aug 24 19:24:20 BRT 2009 mauricio.antu...@gmail.com * All New patches: [All mauricio.antu...@gmail.com**20090824222420 Ignore-this: e09fe2a2596b6e041c7297efcaad55cb ] adddir ./BaseName addfile ./BaseName/JustAtexit.hs hunk ./BaseName/JustAtexit.hs 1 +module BaseName.JustAtexit where +import Foreign +import Foreign.C + +foreign import ccall atexit :: FunPtr (IO ()) -> IO CInt + + addfile ./Setup.hs hunk ./Setup.hs 1 +#!/usr/bin/env runhaskell + +module Main (main) where +import Distribution.Simple + +main = defaultMain addfile ./teste.cabal hunk ./teste.cabal 1 +cabal-version: >= 1.2.3 +name: teste +version: 0.0.1 +synopsis: + Test +description: + Test +version: 1 +license: BSD3 +build-type: Simple +library + hs-source-dirs: . + extensions: +ForeignFunctionInterface + build-depends: base >=3 && <5 + exposed-modules: +BaseName.JustAtexit Context: Patch bundle hash: b4c77eef776e4e5c0b7266156fe638c82a6ab1da ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Linking problem with GHCi
With a specific package (bindings-common, with the latest version in hackage) if I ask GHCi to read it I get: ghc-6.8.2: /home/mauricio/lib/bindings-common-0.2.5/ghc-6.8.2/HSbindings-common-0.2.5.o: unknown symbol `atexit' If I build a library or executable cabal package depending on it, I have no problems. Also, if I remove that 'atexit' wrap from 'bindings-common' I don't get this ghci error message anymore. Why would just this 'atexit' function be a problem? It's wrap does work well, and I can use it from a Haskell program through bindings-common (although not in ghci, of course). This happens at least in ghc-6.8.2 and 6.10.3. Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: simulation in the haskell way
When I was using C and Python, I used to think of most applications in an simulation way. I think it's right to say that programs are simulations. But now I have to change my mind in Haskell, I have to think in a data-flow way, that is: data in, processing using function composition, data out. You have to think there's no in and out, since there's no state and so no before and after. And no flow, since time is just an ilusion of users. In Haskell, a program just "is". Sorry, could not resist the Jedi talk... Hope you like the language. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: simulation in the haskell way
...) But for simulation kind-of problems, in which I think OO really fits the best, what's the haskell way to structure such problems? I once thought maybe I can use the State monad to simulate objects. But it's really hard for me to implement, because I think State monad is used to simulate a global shared state, is it right? Then what's the best way to simulate private states or just instead how to solve simulation problems such as a physical engine using the haskell way? A physical engine can be simulated using pure code, with a function from timestep to state. (Of course, that doesn't hold when you want to deal with user interaction.) I think there is no general answer to your question. My sugestion is to describe an example you would like to work with. Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANN: OpenCLRaw 1.0.1000
> I've released a raw binding to the OpenCL platform on > Hackage. The main differences between it and the C bindings are > that constants have been replaced by newtypes for type safety > reasons, (...) If you think there's something I could change in the package below to make it usefull for this kind of work in the future, please let me know: http://hackage.haskell.org/packages/archive/bindings-common/0.2.5/doc/html/Bindings.html Although, design decisions are pretty different, so may be it would not help, but I thought it worth sugesting. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Blank definition list in haddock
I read in haddock documentation that we write definition lists like this: [...] Did I used those definitons the wrong way? I think the problem is that you have written normal comments instead of Haddock comments. Try adding a | in front of the paragraphs, or just merge them all into one Haddock comment by inserting "--" in front of the blank lines in between your paragraphs. OK. Sent the patch below to haddock maintainer. Thanks, Maurício %%% Paragraphs - One or more blank lines separates two paragraphs in a - documentation comment. +One or more blank lines separate two paragraphs in a +documentation comment. Such blank lines, though, should +still be commented, or they would interrupt Haddock +documentation. %%% ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Blank definition list in haddock
I read in haddock documentation that we write definition lists like this: -- [...@something@] Definition of something. However, using that structure to document many itens, I get a blank list of definitions, like you can see in this section ('Macros') of the documentation for a package of mine: http://hackage.haskell.org/packages/archive/bindings-common/0.2.2/doc/html/Bindings.html#3 However, as can be seen in the source code, there are many definitions inside 'Macros' section. http://hackage.haskell.org/packages/archive/bindings-common/0.2.2/doc/html/src/Bindings.html Did I used those definitons the wrong way? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Finalizers on FunPtrs
I see in Foreign.Ptr documentation that it is good practice to call freeHaskellFunPtr when a pointer to a Haskell function (obtained using 'dynamic' stubs) is not going to be used anymore. Is it possible to do that in a way that is similar to ForeignPtr behavior, where pointers are finalized when GC knows they're not going to be used anymore? See this attempt: In an IO monad: a <- giveMeFunPtr b <- castFunPtrToPtr a :: IO (Ptr something) foreignFunPtr <- newForeignPtr funPtrFinalizer b :: IO (ForeignPtr something) With funPtrFinalizer a FunPtr to: baseFunPtrFinalizer p = freeHaskellFunPtr . castPtrToFunPtr p Is something like that expected to work, i.e., would I get a ForeignPtr that I could cast and give to foreign functions, and still expect that my function pointer would be freed when not needed anymore? Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Do you understand posix well?
I've beeing writing a low-level binding to posix that can be usefull if you want to use posix but has no time to learn FFI: http://hackage.haskell.org/package/bindings-posix However, my understandment of posix is barely nothing, and I see that many of its functionality is enabled or disabled by macros, and I don't know which ones are related to what functionality. So, if you know about that: would you be able to list all macros (or at least most important ones, if there are too many) that enable all (or most) of posix? In exchange, you get a posix binding that is actually comprehensive :) Thanks, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Space for commentaries on hackage
>> Sure! Replace "anonymous" for "easy to write". [...] > [...] every package I upload to hackage includes my email > address in the "maintainer" field, and I love getting emails > from people who use anything I maintain (even if they're asking > me to do work! I may not do it, but it's nice to know that > people care). My motivation for this post is that I'm also interested on the comments from those who don't :) Seriously, it may be usefull to get comments like "why would I use this, if package X already do that better?" But, for politeness if for no other reason, people won't write you to say that. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Space for commentaries on hackage
It would be nice to have a place for anonimous In these days of web spam, anonymous is not such a good idea. Sure! Replace "anonymous" for "easy to write". Although, thinking better, this should be something to ask at repository hosters, not at hackage. Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Space for commentaries on hackage
It would be nice to have a place for anonimous comments below each page of a hackage package, maybe with a cabal option to enable/disable that for a particular package. Authors of packages with few users may want that as a way to get first impressions on their work they would otherwise not get. (At least, I am, so I thought maybe others probably would.) Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Adding a field to a data record
Suppose you have a data type like: Data Foo = Foo { a :: Int, b :: Int, ... many other fields ... y :: Int } deriving (Eq, Read, Show, Typeable, Data) Now I would like to add a field z :: Int to the end of Foo. If I have a ton of data out on disk, which I wrote with, say writeFile "a.data" (show foo) -- where foo is a [Foo] say 1000 long, I would like to get a new "a.data" file which has a new z::Int field. This seems to depend on what you want to accomplish. Is your goal just to rewrite this whole file? If it is, the idea of just adding a field to Foo would be enough. You could then add that 'z' field in your file using 'sed' (or, as you said, emacs) and then read it back. In general, however, if you want to deal with this kind of translation of text to data, what you really want is to take some time to learn something like Parsec. http://www.haskell.org/ghc/docs/latest/html/libraries/parsec/Text-ParserCombinators-Parsec.html So far the only way I can think of is to make a new Data Foo1, which includes the z::Int, read in a.data as a list of Foo, write a function like: fooTofoo1 :: Foo -> Foo1 fooTofoo1 xx = Foo1 {a = a xx, ... y = y xx, z = 1} Note that this would not work exactly like that. 'a' is a "field" of Foo, and that means it's a function like a :: Foo -> Int So, you can't use it as a field of Foo1, as that would imply a :: Foo1 -> Int Best, Maurício ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe