Re: [Haskell-cafe] first the platform, the cabal
Hello Peter, cabal.exe is locatated in extralibs\bin. On my machine the installer added this directory to the PATH, too. Regards, Martin. Peter J. Veger schrieb: I just installed the Haskell Platform 2009.2.0.2 on Windows. There is no cabal.exe, only Cabal-1.6.0.3 How to continue: build cabal? Then what to download from where and what to execute? greetings, Peter J. Veger, Best Netherlands ___ 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] Get data from HTML pages
Hello José, I've done a similar task some weeks ago and I used the Haskell XML Toolbox (hxt) [1] to do this. After learning how to program with arrows it was quite easy to write arrows that extract the relevant information from XML data. Regards, Martin. [1] http://hackage.haskell.org/package/hxt José Romildo Malaquias schrieb: Hello. I am porting to Haskell a Java application I have written to manage collections of movies. Currently the application has an option to indirectly import movie data from web pages. For that first the user should access the page in a web browser. Then the user should copy the rendered text in the web browser into an import window in my application and click an import button. In response the application parses the given text and collects any relevant data it knows about, using regular expressions. For instance, to get the director information from a movie in the AllCenter web site I use the following regular expression: ^Direção:\s+(.+)$ I want to modify this scheme in order to eliminate the need to copy the rendered text from a web browser. Instead my application should download and parse the HTML page directly. Which libraries are available in Haskell that would make it easy to get content information from a HTML document, in the way described above? Regards, Romildo ___ 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] List spine traversal
Hi Andrew, you will find it there but it's written in German. http://opus.kobv.de/tuberlin/volltexte/2008/1755/ Regards, Martin. Andrew Hunter schrieb: 2009/7/1 Matthias Görgens matthias.goerg...@googlemail.com: As a side note, (allowing seq and unsafePerformIO if necessary) is it possible to implement a map that preserves cycles (instead of transparently replacing them with infinite copies? Not horribly useful, but would be quite cute. Baltasar Trancon y Widemann gave a talk on a generalized version of this problem at HaL4. Short answer: The problem is tractable in theory, but you need heavy math. Pretty cool--any paper/slides/transcript/video? AHH ___ 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] GHCI Curl under Windows
Hi Haskellers, I've installed the newest Haskell Platform under Vista and downloaded a pre compiled version of curl-7.19.4 for MinGW. After changing the build type in curl.cabal to Simple and supplying the needed paths I could even build and install curl for haskell. If I write a program using curl and compile it with GHC everything works fine. But if I try to execute the main function of my program in GHCI I always get the following error message: Loading package curl-1.3.5 ... linking ... interactive: C:\Devel\Haskell\curl-1.3.5\ghc-6.10.3\HScurl-1.3.5.o: unknown symbol `__imp__curl_easy_getinfo': unable to load package `curl-1.3.5' Did anybody have the same problem and knows how to fix it? Thanks in advance, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Unfold fusion
Adrian Neumann schrieb: Hello, I'm trying to prove the unfold fusion law, as given in the chapter Origami Programming in The Fun of Programming. unfold is defined like this: unfold p f g b = if p b then [] else (f b):unfold p f g (g b) And the law states: unfold p f g . h = unfold p' f' g' with p' = p.h f' = f.h h.g' = g.h Foremost I don't really see why one would want to fuse h into the unfold. h is executed once, at the beginning and is never needed again. Can someone give me an example? Maybe you should read the euqation from the other direction. Then the h becomes fused out and is called only once instead of many times. But you can only do this if you can factor out h from p', f' and g'. So, this is what I got so far: unfold p f g.h = (\b - if p b then [] else (f b): unfold p f g (g b).h = if p (h b) then [] else (f (h b)) : unfold p f g (g (h b)) = if p' b then [] else f' b: unfold p f g (h (g' b)) not very much. I kinda see why it works after I unfold some more, but I can't really prove it. I suspect I need some technique I haven't learned yet. I've heard about fixpoint induction, that looks promising, but Google knows very little about it. I hope somebody can give me some hints. Regards, Adrian Regards, Martin. ___ 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: Grouping - Map / Reduce
Dear Günther, the map can't be consumed while it is constructed. At any point during its construction you don't know for any key in the map if it will appear in the not cosumed rest of the list again. This means you can't process any entry of the map because it may change later. The only point when nothing will change anymore is when the map is completely constructed. Regards, Martin. Günther Schmidt schrieb: Hi Ketil, Ketil Malde schrieb: Gü?nther Schmidt gue.schm...@web.de writes: let say I got an unordered lazy list of key/value pairs like [('a', 99), ('x', 42), ('a', 33) ... ] and I need to sum up all the values with the same keys. So far I wrote a naive implementation, using Data.Map, foldl and insertWith. Data.Map.fromListWith (+) The building of this map is of course a bottleneck, the successive processing needs to wait until the entire list is eventually consumed the Map is built and flattened again. Sure this is not an artifact of the laziness of foldl? well I can't really see how the map could be consumed *while* it's still being built, I just don't see it. (I'm using foldl' and insertWith', sry for not saying so initially). Is there another way of doing this, something more streaming architecture like? I don't see how you can do this much better - for a small, fixed set of keys, you could use an (STU) array for the sums, but it depends if the added complexity is worth it. You're already doing a single pass over the data. -k ___ 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: memory issues
ChrisK schrieb: Bulat is right about making Block's fields strict. -- | Get the offsets between entries in a list getSizes :: [Integer] - [Integer] getSizes (x:y:[]) = [y - x] getSizes (x:y:ys) = (y - x):(getSizes (y:ys)) You should change the first part to add maxSize: getSizes :: [Integer] - [Integer] getSizes (x:y:[]) = [y - x,maxSize] getSizes (x:y:ys) = (y - x):(getSizes (y:ys)) This avoids the ugly use of (++) below. Note that appending to a singly linked list is a bad code smell: But Chris' version changed semantics. It should be getSizes :: [Integer] - [Integer] getSizes (x:y:[]) = [y-x,maxSize-y] getSizes (x:y:ys) = (y-x):getSizes (y:ys) instead. But getSizes :: [Integer] - [Integer] getSizes [x] = [maxSize-x] getSizes (x:y:ys) = (y-x):getSizes (y:ys) is even better as it doesn't repeat the y-x term. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Supplying a default implementation for a typeclass based on another class
Hi, you could do something like instance (Show a,Read a) = Binary a where put = put . show get = fmap read get But then you will need the following language extensions: FlexibleInstances, OverlappingInstances, UndecidableInstances I don't know how safe this is but it seems to work. Regards, Martin. Svein Ove Aas schrieb: I'm in the process of writing a distributed filesystem (in haskell, yay), which of course means I'm using Binary for de/serialization. Now, that's fine enough, but for simplicity (and for wireshark), I'd like to be able to have Binary fall back on an instance based on Show/Read for any type that lacks any other Binary instance.. Well, I understand why this would be somewhere between extremely hard and impossible in haskell '98, but I'm not entirely up on all the extensions, so I thought I'd ask - given every extension implemented in ghc 6.10.1, is there any reasonable way to do this? ___ 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] Bug in HLint or haskell-src-exts?
Hello Haskellers, I've got the following piece of code type Memory addr value = Map.Map addr value type Stack item = [item] data MachineState addr value item = MachineState { memory :: Memory addr value , stack :: Stack item } deriving (Show) newtype Machine addr value item m a = Machine { unMachine :: StateT (MachineState addr value item) m a } deriving (Monad, MonadState (MachineState addr value item), MonadTrans, MonadIO) and HLint complains: Machine.hs:20:31: Parse failure, Parse error This is exactly the position of the opening bracket after MonadState. Why can GHC parse this and HLint cannot? Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bug in HLint or haskell-src-exts?
Hello again, I found another problem I dont understand: evalOp :: Op - (Integer - Integer - Integer) evalOp op = case op of Plus - (+) Minus - \x y - max 0 (x-y) Times - (*) brings a parse error, too: Interpreter.hs:92:3: Parse failure, Parse error in expression: DVar [Ident x,Ident ... The mentioned position is the T of Times in the last line. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Bug in Cabal?
Hello haskell-cafe, trying to install ghci-haskeline I got the following error message: $ cabal install ghci-haskeline Resolving dependencies... cabal.exe: dependencies conflict: ghc-6.10.1 requires process ==1.0.1.1 however process-1.0.1.1 was excluded because ghc-6.10.1 requires process ==1.0.1.0 Looks like this is a bug in Cabal or cabal-install? Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Deriving
If you use a newtype the answer to the second question is yes. Just put {-# LANGUAGE GeneralizedNewtypeDeriving #-} in the first line of your module or pass -XGeneralizedNewtypeDeriving to ghc or ghci. Daryoush Mehrtash schrieb: What happens when a type adds driving such as: newtype SupplyT s m a = SupplyT (StateT [s] m a) deriving (Functor http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Functor, Monad http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Monad, MonadTrans, MonadIO) Two questions: How does the deriving implement the instance? Is there a way for me to add my own classes in the deriving? for example newtype . deriving( xyz) Thanks ___ 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] Extensible Exceptions
BTW, the documentation of catch is bad: the example catch (openFile f ReadMode) (\e - hPutStr stderr (Couldn't open ++f++: ++ show e)) does not type check. Is this a known bug or shall I report it anywhere? Regards, Martin. Ross Mellgren schrieb: I think catch is now basically what catchJust was -- you can just do thing_to_try `catch` (\ (ErrorCall s) - putStrLn s) and it will only catch ErrorCall exceptions. -Ross David F. Place wrote: Hi, All. I am trying to understand the new exceptions package in base-4 Control.Exceptions. The documentation for catchJust is the same as in Control.OldException including this example: result - catchJust errorCalls thing_to_try handler Control.OldException provides the predicate errorCalls, but the new one does not. I don't see how to write it. Thanks for reading. Cheers, David ___ 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 mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Problem installing curl
Hi all, when I try to install curl (needed for hxt) using cabal install curl I alwas get the following error message: Resolving dependencies... 'curl-1.3.2.1' is cached. Configuring curl-1.3.2.1... cabal: Error: some packages failed to install: curl-1.3.2.1 failed during the configure step. The exception was: sh: runGenProcess: does not exist (No such file or directory) I don't know what to do here. Can anybody help me please? I'm using the brand new GHC 6.10.1 on Windows Vista. Best regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] flipped IO sequence
Hi Cetin, what you seem to want is warn :: String - IO Int warn = (return 1 ) . putStrLn Cetin Sert schrieb: warn :: String → IO Int warn = return 1 putStrLn-- causes an error -- = \msg → return 1 putStrLn msg -- works just fine -- = \msg → putStrLn msg return 1 -- works just fine () :: Monad m ⇒ m b → m a → m b b a = a = \_ → b Why do I get this compile-time error?? How can one define ? [EMAIL PROTECTED]:~/lab/test/qths/p ghc -fglasgow-exts -O2 -o d64x --make demo2.hs system.hs [1 of 2] Compiling Netman.System( system.hs, system.o ) system.hs:23:14: No instance for (Num (IO Int)) arising from the literal `1' at system.hs:23:14 Possible fix: add an instance declaration for (Num (IO Int)) In the first argument of `return', namely `1' In the first argument of `()', namely `return 1' In the expression: return 1 putStrLn ___ 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] Updated formlets sample?
Hi Chris, you're absolutely right. The mistake was in the where-part of withForm. The function handleOk' gets an environment d as argument but uses an extractor that was created without passing d to runFormState. I've put a corrected version on hpaste [1] and also posted it to the wiki on haskell.org [2]. Hope this is ok for you? Regards, Martin. [1] http://hpaste.org/10568#a1 [2] http://haskell.org/haskellwiki/Formlets Chris Eidhof schrieb: That means that you don't have input0 in your environment, maybe you're passing in an empty environment? -chris On 21 sep 2008, at 12:11, Martin Huschenbett wrote: Hi Chris, thanks for the updated example. Compiling works now. But when I try to run it I alway get error messages like [input0 is not in the data,input1 is not in the data] Regards, Martin. Chris Eidhof schrieb: Hey Martin, On 19 sep 2008, at 04:14, Martin Huschenbett wrote: I found a blog post concerning formlets [1] in the web. Since looks very interesting I tried to compile the sample code with recent versions of HAppS and formlets from hackage. But this didn't work as the API of formlets has changed since this post. I tried to adopt the code to the new API but I was unable to finish this since there is a new monadic context I don't know to handle in the right way. So my question is, is there an updated version of this sample code in the web or has anybody tried to adopt it and can send me the results? Yes, I'm sorry for that. The API is still very immature and due to changes, that's also why it hasn't been officially announced yet. I've just put an updated example at http://hpaste.org/10568, hope that'll work for you. I guess we should build a small homepage / wikipage that always has an up-to-date example. -chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Updated formlets sample?
Hi Chris, thanks for the updated example. Compiling works now. But when I try to run it I alway get error messages like [input0 is not in the data,input1 is not in the data] Regards, Martin. Chris Eidhof schrieb: Hey Martin, On 19 sep 2008, at 04:14, Martin Huschenbett wrote: I found a blog post concerning formlets [1] in the web. Since looks very interesting I tried to compile the sample code with recent versions of HAppS and formlets from hackage. But this didn't work as the API of formlets has changed since this post. I tried to adopt the code to the new API but I was unable to finish this since there is a new monadic context I don't know to handle in the right way. So my question is, is there an updated version of this sample code in the web or has anybody tried to adopt it and can send me the results? Yes, I'm sorry for that. The API is still very immature and due to changes, that's also why it hasn't been officially announced yet. I've just put an updated example at http://hpaste.org/10568, hope that'll work for you. I guess we should build a small homepage / wikipage that always has an up-to-date example. -chris ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Updated formlets sample?
Hi all, I found a blog post concerning formlets [1] in the web. Since looks very interesting I tried to compile the sample code with recent versions of HAppS and formlets from hackage. But this didn't work as the API of formlets has changed since this post. I tried to adopt the code to the new API but I was unable to finish this since there is a new monadic context I don't know to handle in the right way. So my question is, is there an updated version of this sample code in the web or has anybody tried to adopt it and can send me the results? Thanks in advance, Martin. [1] http://blog.tupil.com/formlets-in-haskell/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Real World HAppS: Cabalized, Self-Demoing HAppS Tutorial (Version 3)
Hi, I got your tutorial working. But when running it from ghci an exception raises: *** Exception: _local/interactive_state\current-00: openBinaryFile: invalid argument (Invalid argument) But I found a way to fix this: replace runserver 5001 by withProgName happs-tutorial $ runserver 5001 Regards, Martin. Thomas Hartman schrieb: I pushed a new version of happs-tutorial to the online demo at http://happstutorial.com:5001 This is also on hackage: cabal install happs-tutorial. (now version 3.) or darcs get http://code.haskell.org/happs-tutorial for the latest The demo/tutorial has the same basic functionality as the last release -- just a login form essentially -- but a lot more bling now. Like menu link items that change colors when the page is clicked. Also the login form that gives sane error messages. The focus for this release was on explaining how I used StringTemplate with HAppS. Hopefully in version 4 I'll finally get to State and Macid! And hopefully some functionality that actually does something beyond just showing what users have created logins :) Thomas ___ 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] Real World HAppS: Cabalized, Self-Demoing HAppS Tutorial (Version 3)
Hi all, taking a look at this tutorial under Windows Vista I ran into a problem: happs-tutorial depends on HAppS-state which again depends on the unix package which doesn't work under windows. So my question is: is there another way to compile HAppS-State and happs-tutorial on windows? Regards, Martin. Thomas Hartman schrieb: I pushed a new version of happs-tutorial to the online demo at http://happstutorial.com:5001 This is also on hackage: cabal install happs-tutorial. (now version 3.) or darcs get http://code.haskell.org/happs-tutorial for the latest The demo/tutorial has the same basic functionality as the last release -- just a login form essentially -- but a lot more bling now. Like menu link items that change colors when the page is clicked. Also the login form that gives sane error messages. The focus for this release was on explaining how I used StringTemplate with HAppS. Hopefully in version 4 I'll finally get to State and Macid! And hopefully some functionality that actually does something beyond just showing what users have created logins :) Thomas ___ 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] Re: HXT namespace problem
Tim Walkenhorst schrieb: runX $ constA (request TableListRequest) root [] [writeA] writeDocument [(a_indent,v_1)] - writeDocument [(a_indent,v_1), (a_check_namespaces, v_1)] - should do the trick. a_check_namespaces unfortunately didn't do the trick. But using uniqueNamespacesFromDeclAndQNames *before* constructing the root helped. But this was not very well documented. However, thanks for your help. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] HXT namespace problem
Hi all, I'm currently trying to generate XML documents with HXT. Everything went well but I can't figure out how to generate the xmlns:... attributes for the namespaces. My code looks like: runX $ constA (request TableListRequest) root [] [writeA] writeDocument [(a_indent,v_1)] - where writeA generates the actual content. This code generates something like: ?xml version=1.0 encoding=UTF-8? soapenv:Envelope soapenv:Body request:tablelist/ /soapenv:Body /soapenv:Envelope But I want it with XML namespaces, i.e.: ?xml version=1.0 encoding=UTF-8? soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/; xmlns:request=http://www.officematic.de/domas/request; soapenv:Body request:tablelist/ /soapenv:Body /soapenv:Envelope I tried using uniqueNamespaces and uniqueNamespacesFromDeclAndQNames but neither worked. Maybe I used them in the wrong part of code. The tree representation my document looks like: ---XTag / | +---XTag {http://schemas.xmlsoap.org/soap/envelope/}soapenv:Envelope; | +---XTag {http://schemas.xmlsoap.org/soap/envelope/}soapenv:Body; | +---XTag {http://www.officematic.de/domas/request}request:tablelist; and for me this looks like if there is enough namespace information provided. I would appreciate any help, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] A monad using IO, Reader, Writer, State and Error
Hi all, for my current project I need a monad that is an instance of MonadIO, MonadReader, MonadWriter, MonadState, and MonadError. I see two ways for defining such a monad using the mtl. 1) type MyMonad = ErrorT E (RWST R W S IO) and 2) type MyMonad = RWST R W S (ErrorT E IO) I can't figure out what is the difference between these two definitions and therefore which one is more suitable for my problem. Or are the equivalent and it is unimportant which one I use? Or is it even better define a new type like newtype MyMonad a = MyMonad { runMyMonad :: R - S - IO (Either E a,S,W) } and declare instances for all 5 type classes? Thanks for your help in advance, Martin. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: A monad using IO, Reader, Writer, State and Error
Chris Kuklewicz schrieb: Martin Huschenbett wrote: 1) type MyMonad = ErrorT E (RWST R W S IO) 2) type MyMonad = RWST R W S (ErrorT E IO) So (1) gives (Left e,s,w) or (Right a,s,w) and (2) gives (Left e) or (Right (a,s,w)) Due to this fact i decided to use (1). If the operation fails and I get (Left e,s,w) what are the values of 's' and 'w'? Are they the state and the written things that were produced by the last successfull operation? Regards, Martin. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Rank-2-polymorphism problem
apfelmus schrieb: For me, the fourth trial works, at least on f :: (forall s . Num s = Maybe s) - Int f y = case y of Just x - x Nothing - 0 This works, because the compiler knows that x has to have type Int. But if you want to apply a function g :: (forall a. Num a = a) - Int to x before returning, it doesn't work any more. But I need this function application. However, thanks for your help. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Rank-2-polymorphism problem
Martin Huschenbett schrieb: My thoughts were that for any class C the types Maybe (forall a. C a = a) (I will call it T1 for short) and (forall a. C a = Maybe a) (I will call it T2 for short) are isomorphic. Defining the isomorphism from T1 to T2 is quite simple: iso1 :: Maybe (forall a. C a = a) - (forall a. C a = Maybe a) iso1 (Just s) = Just s iso1 Nothing = Nothing But I don't catch how to define the isomorphism of the other direction (from T2 to T1). I would guess that defining this isomorphism would also solve my problem concerning the SQL stuff. I found the solution to my problem. I just want to post it for others who may come across the same problem. The trick was simply looking at GHC's error message that tells something about ambiguous types. So let T be an arbitrary instance of C then the other isomorphism becomes: iso2 :: (forall a. C a = Maybe a) - Maybe (forall a. C a = a) iso2 s if isJust (s :: Maybe T) then Just (fromJust s) else Nothing Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Rank-2-polymorphism problem
Hi, I'm writing some database code using HSQL and had to stop on a problem with rank-2-polymorphism that I can't solve. The essence of my code is: module Value where import Data.Maybe class SqlBind a where fromSqlValue :: String - a data Field data Value emptyValue :: Field - Value emptyValue _ = ... readValue :: Field - (forall s. SqlBind s = s) - Value readValue _ = ... That works just fine. But now I want a version of readValue that has a Maybe wrapped around the second parameter and that shall call readValue in the case of a Just and emptyValue in the case of Nothing. But I can't figure out how to write this function as I always get compiler errors. My trials were: -- The type I want to get. readValue' :: Field - (forall s. SqlBind s = Maybe s) - Value -- First trial: readValue' fld s = if isJust s then readValue fld (fromJust s) else emptyValue fld -- Second trial: readValue' fld s | isJust s = readValue fld (fromJust s) | otherwise = emptyValue fld -- Third trial: readValue' fld (Just s) = readValue fld s readValue' fld Nothing = emptyValue fld -- Fourth trial: readValue fld s = case s of Just s' - readValue fld s' Nothing - emptyValue fld But none of these trials worked. Is there any solution that works with GHC-6.6 for now? Thanks in advance, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Rank-2-polymorphism problem
Ian Lynagh schrieb: readValue' :: Field - Maybe (forall s. SqlBind s = s) - Value readValue' fld s = if isJust s then readValue fld (fromJust s) else emptyValue fld Thank you very much, that's exactly what I wanted. After reading in the GHC users guide about rank 2 polymorphism I thought that this is not possible. Chapter 7.4.8. Arbitrary-rank polymorphism says: There is one place you cannot put a forall: you cannot instantiate a type variable with a forall-type. So you cannot make a forall-type the argument of a type constructor. So these types are illegal: x1 :: [forall a. a-a] x2 :: (forall a. a-a, Int) x3 :: Maybe (forall a. a-a) Maybe the users guide is not precise enough at this point. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Rank-2-polymorphism problem
Hi again, the solutions/proposals of Ian and Iavor seem to be exactly what I need at a first glance. But looking at them more in detail reveals some other problems. I also have got a function getFieldValueMB :: SqlBind s = Statement - String - Maybe s To get Ians approach working I would need a function of type getFieldValueMB' :: Statement - String - Maybe (forall s. SqlBind s = s) and for Iavor approach I would need a function of type: getFieldValueMB' :: Statament - String - Maybe Binder which are almost the same. The remaining problem is: How can I construct either of these functions? My thoughts were that for any class C the types Maybe (forall a. C a = a) (I will call it T1 for short) and (forall a. C a = Maybe a) (I will call it T2 for short) are isomorphic. Defining the isomorphism from T1 to T2 is quite simple: iso1 :: Maybe (forall a. C a = a) - (forall a. C a = Maybe a) iso1 (Just s) = Just s iso1 Nothing = Nothing But I don't catch how to define the isomorphism of the other direction (from T2 to T1). I would guess that defining this isomorphism would also solve my problem concerning the SQL stuff. So, is there anybody who knows how to define this isomorphism in a way that GHC-6.6 can compile it? Thanks for you help in advance, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Foralls in records
Hi, instead of writing a function getTransaction that retrieves the connection you could write a function withConnection that doesn't return the connection itself but performs an operation on the connection: withConnection :: (forall c. Connection c = c - Transaction a) - Transaction a withConnection f = Transaction (\t@(TransactionT c) - let Transaction tf = f c in tf t) Then execute becomes: execute :: String - Transaction () execute s = withConnection (\c - connectionExecute c s) Regards, Martin. getConnection :: Transaction c getConnection = Transaction (\t@(TransactionT c) - (c, t)) class Connection c where connectionExecute :: c - String - Transaction () execute :: String - Transaction () execute s = connectionExecute getConnection s ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: nested maybes
Hi, I've often got the same pattern with nested Maybes but inside the IO monad (sure this could be every other monad too). Assuming that I've got functions: getInput :: IO (Maybe Input) processInput :: Input - IO (Maybe Result) printError :: IO () printResult :: Result - IO () I observed me writing something like main :: IO () main = do minput - getInput case minput of Nothing - printError Just input - do mresult - processInput input case mresult of Nothing - printError Just result - printResult result several times. But to my mind this looks very imperative and I hope it can be done more functional. If there is any way, please let me know. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: embedding haskell into html
Hi, I am new to haskell, and now working on embedding haskell into html. Thus we will write webapp using haskell as server-side language like php. Here I explain my plan and ask some questions, looking for experienced ones to discuss with. Maybe you should look at http://www.haskell.org/haskellwiki/Libraries_and_tools/Web_programming first. As far as I know Haskell Server Pages and HASP are doing the same as you want to do. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: IO in lists
Hi, It's probably eaiser to work with normal lists: listChars :: IO [Char] listChars = do c - getChar if c == 'q' then return c else liftM2 (:) (return c) listChars But that is not lazy any more, is it? The idea of the OT was, I think, that he can use the first elements of the list even before the last one was entered. But it's possible to make it lazy again using System.IO.Unsafe.unsafeInterleaveIO: listChars :: IO [Char] listChars = unsafeInterleaveIO $ do c - getChar if c == 'q' then return c else liftM2 (:) (return c) listChars Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Generating Source Code with Haskell
Hi, my aim is to transform an XML file into C++ source code with a Haskell program. The part that parses the XML is already finished (using HaXML) but the part that generates the C++ code is still remaining. Is there already any work on this topic? Maybe even on generating Java or any other object oriented or imperative language. My first approach was to simply generate the C++ code as text using a pretty printing library but this becomes ugly very fast. Next I thought about generating and rendering the AST of the resulting C++ code. But I don't want to reinvent the wheel. Regards, Martin. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
IORefs, MVars und CVars
I just started some multithreaded programming and as I am a newbie, I've gat a question. 1.) What are the differences between IORefs and MVars? 2.) What are CVars for? Thanks, Martin. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: ffi
$ ghc -ffi -o myprog Main.hs cfile.o When I try this I also get an error: martin:~/work/prograemmelchen ghc -ffi -o myprog Main.hs cfile.o ghc-5.02.2: unrecognised flag: -ffi Usage: For basic information, try the `--help' option. Do I use a wrong GHC version? THX, Martin. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: ffi
-fffi three fs This time I also get an error: martin:~/work/prograemmelchen ghc -fffi -o myprog Main.hs cfile.o ghc-5.02.2: unrecognised flag: -fffi Usage: For basic information, try the `--help' option. Main.hs looks like: module Main ( main ) where foreign import ccall cfun cfun :: IO () main :: IO () main = do cfun Is the error here? ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
ffi
Hi all, I've got a simple question concerning FFI but as I am a newbie I don't know the answet. I've got a C-source-file, maybe something like: //cfile.c void cfun() { /* ... do something ... */ } //EOF and a Haskell-source-File, maybe something like: -- Main.hs module Main where main :: IO () main = do -- do something cfun -- I wan't to call the function written in C here -- do again something -- EOF And now my question is: How do i realize this? Can you please tell me how write a binding and how tu run ghc. Thank you very much, Martin. ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
HDirect
Hi all together! Is there any newer version of HDirect than 0.17? Maybe an CVS-repository? THX, Huschi! ___ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe