[Haskell-cafe] Dealing with incoherent instances
I'm looking at GHC's overlapping instances docs here: http://web.mit.edu/ghc/www/users_guide/type-extensions.html#instance-decls and I've ran into the incoherent instances problem. Basically, I have a catch all instance that handles all types in a generic manner using SYB introspection, and then I have type specific instances that specialize behavior for certain types. This works with overlapping instances extension but whenever I take advantage of this functionality from polymorphic functions I run into the incoherent instances. If I enable incoherent instances GHC always picks the general case which seems like the wrong thing to do. What I want it to do is delay comitting to an instance until it's processing a specific invocation of a polymorphic function. All the information is available at compile time but I found no way to do this. Is there a way to get around this problem? Thanks, - Slava. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[2]: [Haskell-cafe] Dealing with incoherent instances
Ok, I think I solved the problem. It actually simplified my design and made it significantly cleaner and nicer :) I won't bore people with the code/explanation here but I'll publish an article about it on defmacro. Actually what I was trying to do is described in the SYB 3 paper. Thanks, - Slava. On 12/27/06, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Vyacheslav, (returning to cafe) Wednesday, December 27, 2006, 6:10:30 PM, you wrote: Ah, so the moment something is passed through a polymorphic function its type information is lost... This seems like a bug in the specification/implementation, no? This is most certainly not the desired behavior. It seems like the compiler has all the information it needs but still can't select the right instance. sorry, but i think that it is how type class system should work in this case. look at the page for details Are there ways to get around this problem? existential types, for example. we need exact specification of your problem. show me the code are you seen http://haskell.org/haskellwiki/OOP_vs_type_classes ? -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Data.Generics question
Sorry, I sent the email to the wrong place and messed up the code (it's early :)). Take two: transform = everywhere (mkT transform') where transform = (\Term a-Flattened a) `extT` (Contstant a-Flattened a) On 12/19/06, Vyacheslav Akhmechet [EMAIL PROTECTED] wrote: That should be pretty simple. This code probably won't work, but you can use it as an example to look into this further. transform everywhere = (mkT transform') where transform = (\Term a-Flattened a) `extT` (Contstant a-Flattened a) Something like this should work. Look into the docs for more info. On 12/19/06, Grote Collective [EMAIL PROTECTED] wrote: Hello all, I have two datatypes, both representing the same language. However, one is a flattened version of the other. For instance: data Flattened = Const Flattened | Sum Flattened Flattened | ... | IntConst Int | RealConst Float | BoolConst Bool | Void data Term = Const Constant | Sum Term Term | ... data Constant = IntConst Int | RealConst Float | BoolConst Bool | Void Now I want to create functions to convert between these two datatypes. This is easy to do but *very* tedious in its most naive approach. However, I think I can use Data.Generics to make a simple implementation of both functions. The question is: can I? I think that this conversion is a simple fold over the structure, changing merely the constructor name (the qualified name, because the unqualified name is the same), but I cannot seem to understand from the documentation how to do this... Thanks in advance, Mark Smith ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Writing Haskell For Dummies Or At Least For People Who Feel Like Dummies When They See The Word 'Monad'
The way to write the book, I think, would be to take something referred to as real world problems - problems a large proportion of programmers deals with and gets paid for, and then show how to solve these problems in Haskell (preferrably quicker and easier than with conventional solutions). I would divide the book into two parts. The first part would introduce Haskell via traditional small examples. Quick sort, towers of Hanoi, etc. The second part would have two or three large examples - something that people would relate to. I'd take a web application, tetris, and perhaps a chat server. Thanks, - Slava. On 12/11/06, Kirsten Chevalier [EMAIL PROTECTED] wrote: On 12/11/06, Patrick Mulder [EMAIL PROTECTED] wrote: In my opinion it would be important to increase the understanding about semantics and processes. And it would be good to introduce the concepts in a similar way as Profokiev introduces the sound of classical music in Peter and the Wolf. If my suspicion is correct, functional programming would be very close to composing classical music (or concurrent algorithms and processes). Has anyone of you similar thoughts on music and programming ? What are the basic ingredients for making abstractions (like in music rythm, keys, tempo, ...) ? It would be useful to express different ways of expression by explaining first semantics of processes and abstractions. I love the analogy, though it's been at least eleven years since I tried to compose any music. (Coincidentally, eleven years ago was when I learned to program...) I've often thought that reading code (if it's well-written code) is a little like reading a poem, which of course is also a little like listening to classical music. There's certainly a sense of rhythm involved in how you choose variable names: that's why nobody likes variable names like theHashTableThatStoresMappingsBetweenNamesAndEmails. I'm not sure what the analogy with keys would be. Maybe writing in a point-free versus a pointed style is sort of like transposing a melody into another key. For the potential book, I definitely think a Peter-and-the-Wolf-like idea is good. (The wolf would be unsafePerformIO, obviously.) Probably any metaphors that assume any knowledge of music should be left for a different piece of writing that assumes a different audience, but pursuing it would be fun. I've been thinking a lot lately about how to present computer science (and programming languages) to a popular audience, too. I don't remember who originally posed the question of who's going to be the Carl Sagan of computer science?, but it's a question somebody should try to answer. (The answer isn't Douglas Hofstadter, because obviously somebody needs to be out there explaining why languages with static type systems are cool, too.) Cheers, Kirsten -- Kirsten Chevalier* [EMAIL PROTECTED] *Often in error, never in doubt Are you aware that rushing toward a goal is a sublimated death wish? It's no coincidence we call them 'deadlines'. -- Tom Robbins ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: File locked unnecessarily
Yes. I've run into similar issues with hs-plugins (albeit not the same). What platform are you running on? How are you compiling your code? Try compiling it with the -threaded flag and see if it fixes your problem. On 12/6/06, Arie Peterson [EMAIL PROTECTED] wrote: Ian Lynagh wrote: Does anyone know what could cause this locking and/or how to prevent it? Nothing else springs to mind. Are you able to send an example that shows the problem? (obviously the smaller the example, the better). I'll try to cut down the offending program to a workable size. This will take a while. By the way, the rewrite I mentioned (which introduced the unwanted locking) did not touch the code which deals with the file, but it did change the program to load that code dynamically (using hs-plugins). Could that possibly be related to the file locking problem? Thanks, Arie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] SYB, ext1Q, and deriving custom Typeable and Data instances
Hi, I'm trying to use SYB to implement some basic relational persistance. I define a PKey datatype to represent primary keys like this: newtype PKey a = PKey a deriving (Show, Typeable, Data) I then define a sample data type like this: data User = User { id :: PKey Int, firstName :: String, lastName :: String, } deriving (Show, Typeable, Data) Finally, I try to iterate over the structure like this: test = gmapQ (gshow `ext1Q` aux) where aux :: PKey a - String aux _ = test The problem is that for id gmapQ calls gshow instead of my customized version (aux). I've seen a discussion on this on haskell cafe at the following URL: http://www.opensubscriber.com/message/haskell-cafe@haskell.org/2167871.html I couldn't understand the following details: 1. Do I need to derive both Typeable and Data instances? 2. Do I need to derive them for both PKey and User or just PKey? 3. Where can I find sample code to derive these instances? Documentation shows a sample of how GHC derives Data, is that a good template to use? Also, what's a good example to derive Typeable (if in fact it needs to be done manually)? Thanks, - Slava. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] File locked unnecessarily
Are you using hGetContents? If you are, take a closer look at the documentation. The function creates a lazy stream and until you finish reading from it the file will be in the semi-closed state (which means it will be locked). On 12/3/06, Arie Peterson [EMAIL PROTECTED] wrote: Hi, After a partial rewrite of my webserver, it is suffering from locked files: /path/to/file: openBinaryFile: resource busy (file is locked) The file in question really shouldn't be locked: - Only my server knows of the file's existence. - Only one thread accesses the file. - The thread accesses the file multiple times in quick succession, opening and closing it each time, but debugging statements show that it is properly closed before it is reopened. I tried opening, reading/writing and closing a file continuously for some time in an isolated environment, and that works without problems. Also, my server did not have this file locking problem before the rewrite, and the rewrite did not touch the part of the code that accesses the file. This suggests that the locking is somehow triggered by the specific access pattern of my code, if that is even possible. Does anyone know what could cause this locking and/or how to prevent it? I'm using ghc 6.4 on gentoo linux (amd64). Thanks and greetings, Arie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
runghc -fglasgow-exts issues
I need to pass -fglasgow-exts to runghc. It appears that if the first flag to runghc is -f, it treats it as a path to GHC itself. So, I cannot do the following: runghc -fglasgow-exts Test.hs because runghc failes (it says it can't find glasgow-exts). However if I do this: runghc -fc:/ghc/bin/ghc.exe -fglasgow-exts Test.hs it works. Is this the expected behavior? I really don't want to pass full path to GHC in order to simply specify -fglasgow-exts. I could fool runghc by doing this: runghc -v -fc:/ghc/bin/ghc.exe -fglasgow-exts Test.hs and it'll work since the first argument isn't -f, but I really don't want to do this (if I have to, what's a good argument that does nothing?). Thanks, - Slava. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] The Future of MissingH
Until this email I was under the impression that the project is dead. For example, if I go to google and type 'MissingH' the first link is fsf's directory page. When I try to get to MissingH website from there the link appears to be down. I can't really figure out what MissingH includes and where to get it from searching the web, not easily anyway. I think fixing this will go a long way to a more widespread adoption of the library. Thanks, - Slava Akhmechet On 11/24/06, John Goerzen [EMAIL PROTECTED] wrote: On Fri, Nov 24, 2006 at 12:37:10PM -0800, Jason Dagit wrote: On 11/24/06, John Goerzen [EMAIL PROTECTED] wrote: What else should be done to make this a valuable resource for Haskell programmers? And a showcase for what is possible with Haskell? I was going to try MissingH on win32 but when I did it refused to compile due to a dependency on, I think, Posix. It would be great if this could be fixed/relaxed. At the time I was looking forward to trying the logging facilities. That should be completely fixed for a long time now. But I will admit I haven't tried to build the latest version on GHC 6.6. In fact, I wrote an entire module (MissingH.IO.StatCompat) so that Windows users can also enjoy HVFS. -- John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Cabal ^M bug
Cabal appears to have an end-of-line bug. If the .cabal file is created on Windows and the project is installed on a Unix system, the resulting executable ends up having ^M at the end because Cabal doesn't properly handle Windows line termination. If the .cabal file is converted to Unix style, everything installs as expected. I tried to submit a ticket to Cabal via the wiki but couldn't authenticate (guest/haskell, as says on the web page, doesn't seem to work). Also HackageDB link seems to be down. I'm not sure who's maintaining the project, so I'm emaling here. Thanks, - Slava. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Cabals' Paths_pkg and GHCi
Hi, I took advantage of Cabal's data-files feature to allow me to portably store and access data files. Cabal generated a Paths_pkg module that I imported. From Cabal's point of view everything works: I can configure, build, install, and run. However, I can no longer use GHCi with the file that imports Paths_pkg - GHCi simply can't find the module. Is there a good way to fix this issue? Thanks, - Slava. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Concurrency issue with dynamic linker in GHC
Thanks guys! I'll try the streams library and see what happens. Bulat: спасибо! ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Concurrency issue with dynamic linker in GHC
Bulat: I didn't get the chance to use the streams library yet, but could you explain how it would solve my locking problem? The core problem that the runtime under Win32 doesn't have an IO manager still remains, correct? Is anyone looking to fix this issue? If not, how hard would it be for me to fix it? I'd like to get my hands dirty with GHC but I don't think I'll be able to do it without a lot of direction. Thanks, - Slava. On 10/22/06, Donald Bruce Stewart [EMAIL PROTECTED] wrote: bulat.ziganshin: Hello Donald, Sunday, October 22, 2006, 9:04:02 AM, you wrote: can't you define this call as 'safe'? But is it safe. Hmm I get kind of queasy when mucking about in the rts. i don't understand you (because of my weak English). 'safe' specifier is just says that function should be called in _safe_ way that will allow to continue execute other Haskell threads. for functions declared as 'unsafe' GHC uses simplified call method that freezes execution of all Haskell threads until called function will return look for details in http://www.haskell.org/~simonmar/papers/conc-ffi.pdf Yes, I understand this. I just don't know how safe it is to have other threads continue executing while I'm swapping code in and out of the system... foreign import ccall unsafe lookupSymbol c_lookupSymbol :: CString - IO (Ptr a) This could be safe, then, for other threads to continue. Yes. -- Don ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Concurrency issue with dynamic linker in GHC
Also, what would it take for me to fix the GHCi crash on Win32 when a plugin is being loaded? I figured I'll ask before blindly jumping into the code :) ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Concurrency issue with dynamic linker in GHC
I am running ghc 6.4.2 on a Win32 machine. I'm using hs-plugins in one thread and a simple getLine loop in another. It appears that getLine blocks the hs-plugins thread on Win32 (this has been verified to work fine on freeBSD). I've tried various combinations of -threaded flag and forkIO/forkOS and always get the undesireable result. Below is the minimal test case. module Main where import Control.Concurrent import System.Plugins import System.IO -- Main loop main = do hSetBuffering stdout NoBuffering forkIO blah test - getLine putStrLn test blah = do contents - loadPlugin Hello putStrLn contents loadPlugin path = do status - pdynload (path ++ .o) [] [] Prelude.String myTestSym case status of (LoadSuccess _ res) - return res (LoadFailure errors) - return $ concat errors - Hello.hs module Hello where myTestSym :: String myTestSym = Hello 2! Thanks! ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Data.Generics vs. Template Haskell
I am trying to figure out where these two libraries stand in relation to each other and which one is preferred to do generic programming in Haskell. I understand that their goals often intersect but couldn't find any good comparisons. Could someone point me in the right direction? Thanks, - Slava Akhmechet ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Data.Generics vs. Template Haskell
-- Forwarded message -- From: Vyacheslav Akhmechet [EMAIL PROTECTED] Date: Aug 24, 2006 5:35 PM Subject: Re: Data.Generics vs. Template Haskell To: Bulat Ziganshin [EMAIL PROTECTED] Ok, so there are two aspects that I can see here. One such aspect is ability to reflect on types (at runtime or compile time). An example of that is creating an automatic mapping from relational databases to haskell newtypes. Another aspect is being able to get an a representation of Haskell code AST in terms of Haskell datatypes in order to be able to process Haskell ASTs in Haskell. As far as I can see the first aspect is a subset of the second because all Haskell types are known at compile time. If this is the case, why the need for two libraries (I am not counting DriFT because it looks like it hasn't been maintained for a long time)? Or am I missing something? Additionally, which one is more maintained and has the most potential to become standard (whether de facto or real) in the future? On 8/24/06, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Vyacheslav, Thursday, August 24, 2006, 11:51:46 PM, you wrote: I am trying to figure out where these two libraries stand in relation to each other and which one is preferred to do generic programming in Haskell. I understand that their goals often intersect but couldn't find any good comparisons. Could someone point me in the right direction? search for generics on hswiki, you should find a lot of papers. in particular, there is a new paper that compares many different approaches to generic programming. in particular, TH is not g.p. tools, it's just a universal Haskell code generator whcih can be used to solve particular tasks in this area. but to solve general problem of defining traversal function what has some general case and a nu,ber of type-specific cases TH is not very appropriate TH (and DriFT) are widely used to generate instances like the haskell compiler itself generates instances for Eq/Show/... and TH, unlike many g.p. tools does it at compile-time. using TH, you also get access to field/constructor names summary: if your task fits into the features provided by g.p. tools, you will gain a much time using them. if your task need compile-time code generation (so that generic program will be no slower than hand-written one) or you need some advanced features which your g.p. tool doesn't provide - welcome to TH with all its programming oddities. development of TH routines for g.p. is an order of magnitude slower (at least!) than doing the same with specialized tool -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Default bufferring behavior
I encountered the following issue last night. Writing a program like this: main = do putStr x - getLine putStr x behaves as expected in hugs and ghci (first prints , then waits for input, then prints the input). However, when compiling and running an executable via ghc, the behavior was very different. I saw a blank console screen and when I typed something it was echoed back to me (as in 25) only after I hit enter. This is trivially fixed by flushing: main = do putStr hFlush stdout x - getLine putStr x or by turning off buffering. Is this the intended behavior? This problem does not appear when using putStrLn (as it flushes automatically) and is quite distracting to newbies. To me it looks like this behavior is at odds with something one can reasonably expect and bufferring should be turned off by default. What do you guys think? Thanks, - Slava. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Graphics library very slow
The latest stable release seems to have some sort of a problem with the graphics library (the general one as well as the wrapper used in SOE). Opening a window takes more than a couple of minutes (on Windows XP). When I run an identical version of the code through Hugs, the window opens immediately. Am I doing something wrong? Thanks, - Slava. ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Evaluating expressions in Visual Haskell
Hi, I apologize if this question has been asked before, but I couldn't find an FAQ or the answer online. Does Visual Haskell have support for evaluating expressions? I tried a few things (like highlighting an expression, rightclicking, and looking for evaluate option) but couldn't find anything. If this feature is missing, is it planned? Also, what is a good way to do this together with Visual Haskell? I could, of course, open an interpreter in a command window, load appropriate modules, and evaluate expressions from there but is there a more integrated way? Thanks, - Slava Akhmechet ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users