Re: [Haskell-cafe] inotify-alike for mac os x?
kqueue is the low level interface, but requires that you handle all file system events as they happen, and fast. There is a higher level interface called fsevents (with accompanying daemon fseventsd) which allows you a more calm way to read the file system events. http://developer.apple.com/mac/library/documentation/Darwin/Conceptual/FSEvents_ProgGuide/Introduction/Introduction.html I think launchd just happens to have an integration to kqueue or fseventsd, I'm not sure launching a program every time a file changes would be the best thing :-) -Ross On Dec 4, 2009, at 11:08 AM, David Leimbach wrote: d On Thu, Dec 3, 2009 at 7:55 PM, Gregory Collins g...@gregorycollins.net wrote: Conal Elliott co...@conal.net writes: I'd like to make some FRPish toys that keep files updated to have functional relationships with other files. hinotify looks like just the sort of underlying magic I could use for efficient implementation on linux. Is there any support for mac os x? Could support be either added to hinotify or maybe inotify and a mac-friendly library be abstracted into a common Haskell interface? I'm fine with an imperative interface, since I can abstract into a functional library, which I guess would be a sort of persistent simplified FRP. On Mac BSD you have to use kqueue, and on Windows it's ReadDirectoryChangesW. A platform-agnostic Haskell library for detecting filesystem change notifications is something that I would really appreciate! launchd does everything on mac os x, like literally everything. My mother said if I can't say something good about someone or something then don't say anything at all, and in this case, I'm taking her advice on what I think about launchd, however if you click the link below you might get an idea of how that works on Mac OS X. http://stackoverflow.com/questions/1515730/is-there-a-command-like-watch-or-inotifywait-on-the-mac Dave G -- Gregory Collins g...@gregorycollins.net ___ 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
Re: [Haskell-cafe] inotify-alike for mac os x?
Well, I don't think anything bad will happen, but I think I remember there being no/little buffering, so your program had to be responsive if you wanted to get the events. fseventsd is a daemon on top that keeps logs, so you can read them at leisure. I'm sorry I can't find the original article I had read to learn this, otherwise I'd link you directly so you could make your own judgements. I think the decision between the two is primarily based on your use case. If you are intended to run continuously and handling each event will probably not use that many resources (as to not bog down the system as you receive many file system events), and you need real-time tracking, kqueue is for you. Conversely, if you need to know things changed soon after, but not immediately, and especially if you don't want to be running continuously, then fseventsd is for you. This is my understanding, not having used either directly (I've only used inotify on linux). -Ross On Dec 4, 2009, at 11:39 AM, Svein Ove Aas wrote: On Fri, Dec 4, 2009 at 5:31 PM, Ross Mellgren rmm-hask...@z.odi.ac wrote: kqueue is the low level interface, but requires that you handle all file system events as they happen, and fast. For the purposes of creating a binding in haskell, my preferred way would be to use the low-level interface and build saner abstractions on top of that; it would be trivial to buffer them haskell-side. That said.. you say you have to handle the events fast. What happens if you don't? -- Svein Ove Aas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] inotify-alike for mac os x?
On Dec 4, 2009, at 5:30 PM, Bryan O'Sullivan wrote: On Fri, Dec 4, 2009 at 8:39 AM, Svein Ove Aas svein@aas.no wrote: That said.. you say you have to handle the events fast. What happens if you don't? If you don't handle events quickly, they're typically thrown away by the kernel without you ever getting to read them. That is, for instance, what happens on Linux with inotify. Throwing away events means that your app's internal mirror of the filesystem state becomes wrong, which is Very Bad for most applications that care. (i.e. Ross's assertion than nothing bad will happen is generally not true.) Ah hah yeah, I meant in the context of it won't block the kernel or cause your computer to melt. It varies between applications whether dropping events is bad or not so I wasn't commenting there. However, with inotify you also can't afford to perform a single read system call per event, because that will cause your watch the filesystem event to soak up most of the system's CPU time. So what you have to do is select to listen for there's an event ready to be read, then sleep a little while, then read in the hope that many (but not too many!) events will have been queued that you can all read at once. And at that point, you'll be getting a stale notification about a file or directory that may no longer even exist, or may have changed type. Consider: I create a file f, write data into it, rename it to g, then create a directory named f. You wake up 10 milliseconds later, and the first event you hear about is that a file named f was created. This is all by way of saying that working with filesystem change notification interfaces is extremely subtle and tricky, enormously more so than you'd think on casual inspection. It's very easy to write a program that uses these interfaces in ways that will make it either generate garbage or consume huge amounts of CPU, and in fact the common case is to write a program that does both. Amen. I've written an application that does this kind of work using inotify and it was a nightmare. I think this is why fseventsd was invented for OS X, and I'm not sure if there's any linux equivalent. However, if someone were to write a library that uses kqueue / inotify / win32-call-I-forget-the-name-of-from-earlier-post in a way that is both efficient and correct, that would be totally awesome. -Ross ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] module export question
It looks like it is specified and the intended behavior: From the report, section 5.2: An algebraic datatype T declared by a data or newtype declaration may be named in one of three ways: The form T names the type but not the constructors or field names. The ability to export a type without its constructors allows the construction of abstract datatypes (see Section 5.8). The form T(c1,...,cn), names the type and some or all of its constructors and field names. The abbreviated form T(..) names the type and all its constructors and field names that are currently in scope (whether qualified or not). And then later similarly for imports from 5.3.1: Exactly which entities are to be imported can be specified in one of the following three ways: The imported entities can be specified explicitly by listing them in parentheses. Items in the list have the same form as those in export lists, except qualifiers are not permitted and the `module modid' entity is not permitted. When the(..) form of import is used for a type or class, the (..) refers to all of the constructors, methods, or field names exported from the module. The list must name only entities exported by the imported module. The list may be empty, in which case nothing except the instances is imported. -Ross On Dec 1, 2009, at 5:18 PM, Luke Palmer wrote: On Tue, Dec 1, 2009 at 3:11 PM, Sean McLaughlin sean...@gmail.com wrote: Say I have the following module: module A ( T(T) , t , val ) where data T = T { t :: Int } val :: T val = T 7 When I use A with the following imports, I don't expect this to work, but it does: import qualified A import A(T(..)) main = putStrLn $ show $ t A.val The problem is that I explicitly didn't export 't' as an element of T (by not writing T(..)). Am I just misunderstanding how exports work? I couldn't figure out what the correct behavior should be by looking at the 98 report. Oh interesting. What a crazy corner case. I also feel like your program shouldn't be valid. Maybe it's a bug? ___ 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] Where is `newTVarIO` defined ?
Control.Concurrent.STM On Nov 24, 2009, at 6:11 PM, zaxis wrote: I cannot hoogle it. It appears in Pugs: run' (-d:rest) = do info - fmap Just (io $ newTVarIO Map.empty) let ?debugInfo = info run' rest Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Where-is-%60newTVarIO%60-defined---tp26504967p26504967.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ 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] Graph drawing library for Haskell
I've written a simple incomplete binding to graphviz-as-a-library to do in-process graphviz layouts, though I would say it's hardly complete so I haven't released it. If it's useful to someone and they want to put in some additional elbow grease to make the particular features they want work, I can throw it up somewhere. -Ross On Nov 20, 2009, at 9:00 AM, Magnus Therning wrote: On Fri, Nov 20, 2009 at 1:57 PM, Victor Mateus Oliveira rhapso...@gmail.com wrote: Hi, Anyone knows a good library for graph diagram drawing? Or a haskell binding for one? Something like jgraph. http://www.jgraph.com/jgraph.html I usually turn to graphviz for my Haskell graphing needs. /M -- Magnus Therning(OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe ___ 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: 32 to 64 bit problem
Also /usr/bin/ghci, /usr/bin/runghc, /usr/bin/runhaskell to patch up all the holes. There may be others, also. Here is a reference to the original thread where someone found out SL broke GHC and then worked through temporarily resolving it: http://old.nabble.com/Snow-Leopard-Breaks-GHC-td25198347.html -Ross On Nov 15, 2009, at 8:03 AM, Luca Ciciriello wrote: Thanks a lot Christophe. This solve my problem. Luca. On Nov 15, 2009, at 1:49 PM, alpheccar wrote: Hi, Change your /usr/bin/ghc to #!/bin/sh exec /Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.4/ghc -optc-m32 -opta-m32 -optl-m32 -B/Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.4/. -dynload wrapped ${1+$@} The options -optc-m32 -opta-m32 -optl-m32 must be added. Christophe. Hi All. I think this is a not new question, but probably a missed it. On my MacOS X 10.5 (32 bit) I use GHC 6.10.4 (installed by Mac package GHC-6.10.4-i386.pkg) to build some halkell programs and all is fine. Yesterday I've updated the system to MacOS X 10.6 (64 bit) and now when I try to build the same programs I get the errors: /var/folders/vr/vrW2wwvtFKScalkhVEWujE+++TI/-Tmp-/ghc1613_0/ghc1613_0.s:1167:0: 32-bit absolute addressing is not supported for x86-64 /var/folders/vr/vrW2wwvtFKScalkhVEWujE+++TI/-Tmp-/ghc1613_0/ghc1613_0.s:1167:0: cannot do signed 4 byte relocation /var/folders/vr/vrW2wwvtFKScalkhVEWujE+++TI/-Tmp-/ghc1613_0/ghc1613_0.s:1170:0: 32-bit absolute addressing is not supported for x86-64 /var/folders/vr/vrW2wwvtFKScalkhVEWujE+++TI/-Tmp-/ghc1613_0/ghc1613_0.s:1170:0: cannot do signed 4 byte relocation Is there any solution to continue to use the installed GHC on the new 64 bit system? Thanks in advance for any answer. Luca ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users ___ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: [Haskell-cafe] Why can `env` be assigned value two times ?
They're two different 'env's, which can be observed by desugaring the do-notation: do env - liftIO (readIORef envRef) env - return (filter (\(_id, _) - _id /= id) env) ... Desugaring do-notation gets us: liftIO (readIORef envRev) = \ env - return (filter (\(_id, _) - _id /= id) env) = \ env - ... Sometimes people use different names to make this obvious, e.g. do env - liftIO $ readIORef envRef env' - return (filter ... env) Also note that you're doing a pure operation here, so you don't need two bindings. You could instead do: do env - filter (\(_id, _) - _id /= id) $ readIORev envRef ... ($ is from the supremely useful Control.Applicative, and is equivalent to fmap from Functor, or liftM from Monad) or: do env - liftIO $ readIORef envRef let env' = filter ... env Using let notation here makes it somewhat more obvious that that line doesn't have any side effects. -Ross On Nov 15, 2009, at 2:05 AM, zaxis wrote: defineVar :: Env - (Id, Val) - IOThrowsError Val defineVar envRef (id, val) = do { env - liftIO $ readIORef envRef; env - return $ filter (\(_id, _) - _id/=id) env; -- clear the current scope valRef - liftIO $ newIORef val; liftIO $ writeIORef envRef $ ((id, valRef):env); return val; } In haskell, the variable canot change its value , right? If so, why can the `env` be assigned value twice? Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/Why-can-%60env%60-be-assigned-value-two-times---tp26356073p26356073.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ 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] Problem with JHC
According to the paste you gave for the JHC test run: Here is what happens when I try to run it: phi...@desktop:~/jhctut$ ./jtree Give me a tree: T AND (L 1, L 2) jtree_code.c:2670: case fell off Aborted You gave it parens not square brackets. -Ross On Nov 11, 2009, at 11:45 AM, Philippos Apolinarius wrote: you declared 'T Op [Tree]' so you should give 'T AND [L 1, L 2]' as the tree, right? Hi, Felipe. You are right. This means that I gave the correct input to the program. As you can see, I typed 'T AND [L 1, L 2]'. Therefore, JHC was expected to parse and print it. However, it failed to parse it. The program works perfectly well in GHC. Here is the GHC output: phi...@desktop:~/jhctut$ ghc tree.hs --make [1 of 1] Compiling Main ( tree.hs, tree.o ) Linking tree ... phi...@desktop:~/jhctut$ ./tree Give me a tree: T AND [L 1, L 2] T AND [L 1,L 2] --- On Wed, 11/11/09, Felipe Lessa felipe.le...@gmail.com wrote: From: Felipe Lessa felipe.le...@gmail.com Subject: Re: [Haskell-cafe] Problem with JHC To: haskell-cafe@haskell.org Received: Wednesday, November 11, 2009, 6:23 AM On Wed, Nov 11, 2009 at 04:32:05AM -0800, Philippos Apolinarius wrote: data Op = AND | OR | NOT deriving (Show, Read) data Tree= L Int | T Op [Tree] deriving (Show, Read) Hmm, you see, phi...@desktop:~/jhctut$ ./jtree Give me a tree: T AND (L 1, L 2) jtree_code.c:2670: case fell off Aborted you declared 'T Op [Tree]' so you should give 'T AND [L 1, L 2]' as the tree, right? -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Get the name you've always wanted ! @ymail.com or @rocketmail.com.___ 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] classes question
You did not specify what type of number it is -- in Haskell numeric constants like 1 are actually typed as forall a. Num a -- that is, can be any type of Num. Try: plus (2::Int) 3 -Ross On Nov 9, 2009, at 1:44 PM, Paul Tokarev wrote: Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ 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] classes question
It's not your class definition that is the problem -- your class definition is good. The problem is that when you interact with it using the REPL, you don't specify any particular type you want so it's ambiguous. Usually this is not a problem in actual programs that you compile because there's enough context for the type inferencer to figure out what type 'a' should be. You can give it enough context in the REPL either by annotating the value or by using some other typed thing, e.g. let a = 1:: Int If you really want it to only work on Int, then you shouldn't use a typeclass, instead just write the function directly -- plus :: Int - Int - Int plus = (+) -Ross On Nov 9, 2009, at 5:09 PM, Paul Tokarev wrote: Thanks, that works. But how sould I change my class definition, so that it works without (2::Int), but just with 2? Ross Mellgren wrote: You did not specify what type of number it is -- in Haskell numeric constants like 1 are actually typed as forall a. Num a -- that is, can be any type of Num. Try: plus (2::Int) 3 -Ross On Nov 9, 2009, at 1:44 PM, Paul Tokarev wrote: Hi. I am using Hugs 98 I have that piece of code: class PlusTimes a where plus :: a - a - a instance PlusTimes Int where plus x y = x + y when I run : plus 2 3 I get this error: ERROR - Unresolved overloading *** Type : (Num a, PlusTimes a) = a *** Expression : plus 2 3 What am I doing wrong? Thanks. -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26271257.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ 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 -- View this message in context: http://old.nabble.com/classes-question-tp26271257p26274624.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ 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] Fortran mixed mode arithmetic expressions - Haskell
http://www.haskell.org/onlinereport/basic.html 6.3 Standard Haskell Classes -Ross On Oct 26, 2009, at 3:13 PM, michael rice wrote: Got it. No doubt some of this figures into why I was beaten bloody by ghci last night. Is there a number tree somewhere that shows the heirarchy? Michael --- On Mon, 10/26/09, Daniel Fischer daniel.is.fisc...@web.de wrote: From: Daniel Fischer daniel.is.fisc...@web.de Subject: Re: [Haskell-cafe] Fortran mixed mode arithmetic expressions - Haskell To: michael rice nowg...@yahoo.com, haskell-cafe@haskell.org Date: Monday, October 26, 2009, 1:09 PM Am Monday 26 October 2009 17:24:46 schrieben Sie: Being new to Haskell, I take it (^) and (^^) would be the preferred exponential operator. When (how,where,why) would one use (**)? The beasts have different types and are for different things: Prelude :i (^) (^) :: (Num a, Integral b) = a - b - a -- Defined in GHC.Real infixr 8 ^ This one raises any number to a nonnegative integral power. A typical implementation would be power by repeated squaring. Prelude :i (^^) (^^) :: (Fractional a, Integral b) = a - b - a -- Defined in GHC.Real infixr 8 ^^ This one allows also negative powers, so the type of base must allow inversion, hence it must belong to Fractional. The exponent must still be an integer, you can't use this for n-th roots or similar. A typical implementation would be power by repeated squaring, followed by (1/) if the exponent is negative. Prelude :i (**) class (Fractional a) = Floating a where ... (**) :: a - a - a ... -- Defined in GHC.Float infixr 8 ** This one raises a floating point number to an arbitrary power, so you can use it for n-th roots. A typical implementation would be b ** e = exp (e*log b). ___ 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] x - String
Andrew has mentioned the debugger several times, NOT the interactive REPL. That is, using :-commands to inspect values. -Ross On Oct 16, 2009, at 2:46 PM, Daniel Peebles wrote: My GHCi can't do that :o I just wrote data A = B | C and loaded the file into GHCi. Typing B gives me: interactive:1:0: No instance for (Show A) arising from a use of `print' at interactive:1:0 Possible fix: add an instance declaration for (Show A) In a stmt of a 'do' expression: print it The error also gives an idea of what GHCi is doing behind the scenes: it's just calling print, which has a Show constraint. On Fri, Oct 16, 2009 at 2:40 PM, Andrew Coppin andrewcop...@btinternet.com wrote: Jochem Berndsen wrote: I rephrase: There *is* a way to turn arbitrary values into strings. I know there is, because the GHCi debugger *does* it. The question is, does anybody know of an /easy/ way to do this? No. GHCi does not always do this: Prelude Data.Ratio let plus1 = (+1) Prelude Data.Ratio plus1 interactive:1:0: No instance for (Show (a - a)) arising from a use of `print' at interactive:1:0-4 Possible fix: add an instance declaration for (Show (a - a)) In a stmt of a 'do' expression: print it Prelude Data.Ratio The GHCi *debugger* can print out even values for which no Show instance exists. (But yes, it fails to print anything interesting for function types... It works for ADTs that don't have Show though.) Anybody know of a way to do this? (As it happens, the values I'm testing with are all Showable anyway, but the type checker doesn't know that...) What is the problem with adding a function showMyContainer :: (Show a) = Container a - String ? In this case you can show your container (for debugging purposes), but only if you have Showable elements in your container. This could plausibly work... ___ 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
Re: [Haskell-cafe] x - String
No problem, just trying to make sure the conversation stays on track :-) -Ross On Oct 16, 2009, at 3:26 PM, Daniel Peebles wrote: Whoops, sorry about that then! On Fri, Oct 16, 2009 at 2:59 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: Andrew has mentioned the debugger several times, NOT the interactive REPL. That is, using :-commands to inspect values. -Ross On Oct 16, 2009, at 2:46 PM, Daniel Peebles wrote: My GHCi can't do that :o I just wrote data A = B | C and loaded the file into GHCi. Typing B gives me: interactive:1:0: No instance for (Show A) arising from a use of `print' at interactive:1:0 Possible fix: add an instance declaration for (Show A) In a stmt of a 'do' expression: print it The error also gives an idea of what GHCi is doing behind the scenes: it's just calling print, which has a Show constraint. On Fri, Oct 16, 2009 at 2:40 PM, Andrew Coppin andrewcop...@btinternet.com wrote: Jochem Berndsen wrote: I rephrase: There *is* a way to turn arbitrary values into strings. I know there is, because the GHCi debugger *does* it. The question is, does anybody know of an /easy/ way to do this? No. GHCi does not always do this: Prelude Data.Ratio let plus1 = (+1) Prelude Data.Ratio plus1 interactive:1:0: No instance for (Show (a - a)) arising from a use of `print' at interactive:1:0-4 Possible fix: add an instance declaration for (Show (a - a)) In a stmt of a 'do' expression: print it Prelude Data.Ratio The GHCi *debugger* can print out even values for which no Show instance exists. (But yes, it fails to print anything interesting for function types... It works for ADTs that don't have Show though.) Anybody know of a way to do this? (As it happens, the values I'm testing with are all Showable anyway, but the type checker doesn't know that...) What is the problem with adding a function showMyContainer :: (Show a) = Container a - String ? In this case you can show your container (for debugging purposes), but only if you have Showable elements in your container. This could plausibly work... ___ 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
Re: [Haskell-cafe] Generating random enums
I didn't try to compile this: import Control.Arrow (first) import System.Random (Random(..)) instance Random Dir where randomR (lo, hi) gen = first fromEnum (randomR (toEnum lo) (toEnum hi) gen) random gen = randomR (minBound, maxBound) But something along those lines should help you I think. -Ross On Oct 16, 2009, at 3:36 PM, michael rice wrote: What is the minimum I need to do to get this function to generate a three direction tuple? Michael = import System.Random import Data.Ord data Dir = North | South | East | West deriving (Show, Read, Eq, Enum, Ord, Bounded) threeDirs :: StdGen - (Dir,Dir,Dir) threeDirs gen = let (firstDir, newGen) = random gen (secondDir, newGen') = random newGen (thirdDir, newGen'') = random newGen' in (firstDir, secondDir, thirdDir) = GHCi, version 6.10.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude :l dir.hs [1 of 1] Compiling Main ( dir.hs, interpreted ) dir.hs:15:29: No instance for (Random Dir) arising from a use of `random' at dir.hs:15:29-42 Possible fix: add an instance declaration for (Random Dir) In the expression: random newGen' In a pattern binding: (thirdDir, newGen'') = random newGen' In the expression: let (firstDir, newGen) = random gen (secondDir, newGen') = random newGen (thirdDir, newGen'') = random newGen' in (firstDir, secondDir, thirdDir) Failed, modules loaded: none. Prelude ___ 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] Different semantics in identical do statement?
In what Monad? -Ross On Oct 9, 2009, at 5:43 PM, staafmeister wrote: In my program do x - do blah - someFunc return blah return $ Constructor x behaves differently from do blah - someFunc return $ Constructor blah where the dots are identical. I would think that these programs should behave identically, by the monad laws. The result of my program is that the second gives correct behaviour, while the first loops forever. Greetings, Gerben -- View this message in context: http://www.nabble.com/Different-semantics-in-%22identical%22-do-statement--tp25828319p25828319.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ 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] Let it be
You're running into this problem because you're in a do-block. In a do- block, all the continuing lines of a single statement in the do-block must be indented w/r/t to the first line. The cylinder example doesn't have this issue because it's not in a do-block. The layout rule (I'm summarizing and I haven't read the spec, so someone jump on me if I'm stating the wrong thing) basically says that within some implied { }, ;'s will be inserted for any line that is at the same indentation level as the previous line, e.g. import System.Random main = do gen - getStdGen let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) in putStrLn $ Number is ++ show randNumber has the following implied symbols import System.Random main = do { gen - getStdGen ; let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) ; in putStrLn $ Number is ++ show randNumber } which is now obviously wrong, as the let and in are in two separate statements. Conversely, import System.Random main = do gen - getStdGen let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) in putStrLn $ Number is ++ show randNumber implied: import System.Random main = do { gen - getStdGen ; let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) in putStrLn $ Number is ++ show randNumber } Hope that clarifies things. -Ross On Oct 8, 2009, at 11:43 AM, michael rice wrote: From Learn You a Haskell (Let it be section): 1. cylinder :: (RealFloat a) = a - a - a 2. cylinder r h = 3. let sideArea = 2 * pi * r * h 4. topArea = pi * r ^2 5. in sideArea + 2 * topArea === What's the proper indentation for LET so these problems (below) don't arise? I thought LET and IN should be aligned in the same column. Also, isn't a LET expression an expression. Michael == This works: import System.Random main = do gen - getStdGen let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) in putStrLn $ Number is ++ show randNumber == This works: import System.Random main = do gen - getStdGen let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) putStrLn $ Number is ++ show randNumber == This doesn't: import System.Random main = do gen - getStdGen let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) in putStrLn $ Number is ++ show randNumber [mich...@localhost ~]$ runhaskell zz.hs zz.hs:4:2: The last statement in a 'do' construct must be an expression ___ 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] Let it be
I don't know of any offhand that specifically call it out -- it's a natural consequence of the layout rule which is described in the Haskell Report. However, there is at least one ticket in Haskell' to fix it for if/then/else: http://hackage.haskell.org/trac/haskell-prime/ticket/23 -Ross On Oct 8, 2009, at 1:03 PM, michael rice wrote: Thanks all, So, in a do expression let x = 1 y = 2 etc. in z = 1 + 2 if bool expr then etc. else etc. Is this deviation documented somewhere? Michael --- On Thu, 10/8/09, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: From: Brandon S. Allbery KF8NH allb...@ece.cmu.edu Subject: Re: [Haskell-cafe] Let it be To: michael rice nowg...@yahoo.com Cc: Brandon S. Allbery KF8NH allb...@ece.cmu.edu, haskell-cafe@haskell.org Date: Thursday, October 8, 2009, 11:53 AM On Oct 8, 2009, at 11:43 , michael rice wrote: This doesn't: import System.Random main = do gen - getStdGen let (randNumber, newGen) = randomR (1,6) gen :: (Int, StdGen) in putStrLn $ Number is ++ show randNumber [mich...@localhost ~]$ runhaskell zz.hs zz.hs:4:2: The last statement in a 'do' construct must be an expression The problem here is that the do construct parses things a bit differently; if you're at the same indentation level, it inserts a () on the assumption that the next line is an independent expression, so you need to indent the in a bit more to avoid it. Note however that this usage is common enough that do provides a shorthand: you can simply omit the in, and let will be parsed as if it were a statement: main = do gen - getStdGen let (randNumber, newGen) = randomR (1,6) gen :: (Int,StdGen) putStrLn $ Number is ++ show randNumber -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH ___ 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] New to Haskell - List Comprehension Question
I don't think a list comprehension is the easiest way to do it, how about upperCase :: String - String upperCase [] = [] upperCase (x:xs) = toUpper x : map toLower xs -Ross On Oct 7, 2009, at 4:48 PM, Steven1990 wrote: Hi, I'm currently learning Haskell, and I've been trying to work out a function for the following problem for a couple of days now. I want to use a list comprehension method to change the first letter of a string to upper case, and the rest of the string to lower case. Eg: heLLo - Hello As I'm trying to learn this, I would appreciate hints rather than the explicit solution if possible? I'm sure I'm close to a solution, I must be missing something though. Driving me crazy! My attempts are something similar to this: upperCase :: String - String upperCase xs = [toUpper(x):toLower(xs) | x - xs] I think 'toLower' expects a single character rather than the list which is one place I'm going wrong? Thanks in advance, Steven -- View this message in context: http://www.nabble.com/New-to-Haskell---List-Comprehension-Question-tp25794144p25794144.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com . ___ 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] Creating an alias for a function
car = head letting the compiler infer the type, or car :: [a] - a car = head for the explicit version. -Ross On Oct 6, 2009, at 10:01 PM, michael rice wrote: How do I create an alias for a function, like giving CAR the same functionality as HEAD. I know I can do it by creating a definition (see below), but is there a better way, like Scheme's (define head car) car :: [a] - a car x = head x The reason for doing this is to more closely mirror legacy code. Michael ___ 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] 16 bit floating point data in Haskell?
What about the built-in Float type? Prelude Foreign.Storable sizeOf (undefined :: Float) 4 Prelude Foreign.Storable sizeOf (undefined :: Double) 8 Or maybe you mean something that can be used with FFI calls to C, in which case Foreign.C.Types (CFloat). Both instance the Floating, RealFloat, RealFrac, etc, classes so should operate largely the same as (modulo precision) a Double. -Ross On Sep 27, 2009, at 2:42 PM, Olex P wrote: Hi guys, Do we have anything like half precision floats in Haskell? Maybe in some non standard libraries? Or I have to use FFI + OpenEXR library to achieve this? Cheers, Oleksandr. ___ 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] 16 bit floating point data in Haskell?
Oh sorry, I misread the original question. I take it all back! -Ross On Sep 27, 2009, at 4:19 PM, Peter Verswyvelen wrote: He meant 16-bit floats, which have sizeOf 2 On GPUs this is common and implemented in hardware (at least on the old GPUs). On DPSs you commonly had 24-bit floats too. But these days I guess 32-bit is the minimum one would want to use? Most of the time I just use double anyway :) On Sun, Sep 27, 2009 at 9:47 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: What about the built-in Float type? Prelude Foreign.Storable sizeOf (undefined :: Float) 4 Prelude Foreign.Storable sizeOf (undefined :: Double) 8 Or maybe you mean something that can be used with FFI calls to C, in which case Foreign.C.Types (CFloat). Both instance the Floating, RealFloat, RealFrac, etc, classes so should operate largely the same as (modulo precision) a Double. -Ross On Sep 27, 2009, at 2:42 PM, Olex P wrote: Hi guys, Do we have anything like half precision floats in Haskell? Maybe in some non standard libraries? Or I have to use FFI + OpenEXR library to achieve this? Cheers, Oleksandr. ___ 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
Re: [Haskell-cafe] gtk2hs and runghc
Well, keep in mind forkIO *might* be a different OS thread (unless it's bound, IIRC), depending on the number of workers (with -Nx) and so on. -Ross On Sep 23, 2009, at 2:24 PM, Günther Schmidt wrote: Am 23.09.2009, 19:29 Uhr, schrieb Duncan Coutts duncan.cou...@worc.ox.ac.uk : On Tue, 2009-09-22 at 17:08 -0400, Brandon S. Allbery KF8NH wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On Sep 22, 2009, at 11:31 , Günther Schmidt wrote: Gtk2hs then complains about running in a multithreaded ghc, ie. one with several real OS threads. Is it possible to start runghc single-threaded? No, but you can unsafeInitGUIForThreadedRTS. If you observe the foot-shooting restrictions (of which the easiest is to not use forkIO). Duncan And exactly herein lies the problem :) I've seen your response to the recent post about gui state, in which you mention your own prefered solution to the problem, ie. that you post your state to a channel which is read in a thread. I'm doing the same thing, but I'm also calling gui code from within that thread. I figured since the thread itself isn't a separate OS thread it shouldn't be a problem. It seems to work once the app is compiled, but running the code in either ghci or with runghc it crashes. Günther ___ 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] Is it safe to use unsafePerformIO here?
Ah yeah, that too. Control.Parallel.Strategies.rnf to the rescue? -Ross On Sep 15, 2009, at 4:17 PM, Cristiano Paris wrote: On Tue, Sep 15, 2009 at 10:12 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: Wouldn't seq b only force (at minimum) the first character of the file? I think it force the evaluation of the Cons in the String but not the characters therein. Cristiano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it safe to use unsafePerformIO here?
Ack, IGNORE ME! Way too strict. -Ross On Sep 15, 2009, at 4:20 PM, Ross Mellgren wrote: Ah yeah, that too. Control.Parallel.Strategies.rnf to the rescue? -Ross On Sep 15, 2009, at 4:17 PM, Cristiano Paris wrote: On Tue, Sep 15, 2009 at 10:12 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: Wouldn't seq b only force (at minimum) the first character of the file? I think it force the evaluation of the Cons in the String but not the characters therein. Cristiano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is it safe to use unsafePerformIO here?
Wouldn't seq b only force (at minimum) the first character of the file? -Ross On Sep 15, 2009, at 4:08 PM, Cristiano Paris wrote: On Tue, Sep 15, 2009 at 9:29 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: Am Dienstag 15 September 2009 21:13:02 schrieb Daniel Fischer: Still, the body should be read lazily. I'm not sure, but the tracing message may be output because of its position. With where readBody = withFile fn ReadMode $ \h - do b - hGetContents h seq b $ return (trace (Read body from: ++ fn) b) there's no tracing output. Yes, tested with -rw-r--r-- 1 me users 243M 15. Sep 21:17 file1.txt -rw-r--r-- 1 me users 243M 15. Sep 21:18 file2.txt Ok, Daniel, I got the point: the IO action gets performed but there's no need to use unsafePerformIO as hGetContents is already lazy and the IO action is ineffective anyway when the result is not needed. Yet, I'm still confused as seq b should force the complete execution of hGetContents. So I decided to run a different test: I'm using this code: --- module Main where import System.IO import System.IO.Unsafe import Control.Applicative import Data.List import Data.Ord import Debug.Trace data Bit = Bit { index :: Integer, body :: String } readBit fn = withFile fn ReadMode $ \h - Bit $ (hGetLine h = return . read) * readBody where readBody = trace In readBody $ withFile fn ReadMode $ \h - do b - hGetContents h seq b $ return $ trace (Read body from: ++ fn) b main = do bl - mapM readBit [file1.txt,file2.txt] mapM_ (putStrLn . show . index) $ sortBy (comparing index) bl putStrLn $ body $ head bl (Hope this looks better than before). I ran this on a 115KB-long file1.txt file and traced with dtruss (OSX strace equivalent). You know what? Only the first 1024 bytes of file1.txt are read and actually displayed. So, it seems that seq b is completely ineffective and program is not correct. Cristiano ___ 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] problems with HOC install from svn
It sounds like it's looking for the binary package -- you should install it using cabal, e.g. private (per-user) install: cabal update cabal install binary global (system-wide) install: sudo cabal update sudo cabal install --global binary -Ross On Sep 8, 2009, at 7:57 PM, John Velman wrote: I'm unable to build HOC from the svn read-only checkout. Here are some details of what I'm doing. I'm running OS X 10.5.8 on an intel iMac with Xcode is 3.1.3. Haskel and Cabal are from the Haskel platform, haskell-platform-2009.2.0.2-i386.dmg I got Parsec 3.0 from Hackage. I checked out HOC using the svn command at http://code.google.com/p/hoc/source/checkout and checked out revision 411. Configure goes OK except for the complaint: Setup.hs:1:0: Warning: In the use of `defaultUserHooks' (imported from Distribution.Simple): Deprecated: Use simpleUserHooks or autoconfUserHooks, unless you need Cabal-1.2 compatibility in which case you must stick with defaultUserHooks But when I try to build, I get, after a bunch of apparently successful things: --- Loading package binary-0.5.0.1 ... command line: can't load .so/.DLL for: HSbinary-0.5.0.1 (dlopen (libHSbinary-0.5.0.1.dylib, 9): image not found) --- I certainly can't find libHSbinary... of any version on my computer, dylib or not. Tried looking in the /Library/Frameworks/GHC.Framework stuff, also did a find . -iname *libHS* and found libHSGLFW..., libHSparsec-3.0.0. (also tried this in my home directory). What is this, and how do I get it? Best, John Velman ___ 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] problems with HOC install from svn
I have binary-0.5 not binary-0.5.0.1, but it doesn't have any dylibs. Moreover, I was under the impression that GHC does not yet support shared libraries like those, so I'm not sure why it would be looking for one. I can't really speculate, maybe more of the build output might help? -Ross On Sep 8, 2009, at 10:54 PM, John Velman wrote: Thanks. Now I do have libHSbinary-0.5.0.1.a in /usr/local/lib, but apparently not the dylib version. Tomorrow I'll look further. Perhaps there are some options to produce dylib libraries. I've used Haskell on Linux some time ago (but not Cabal), and have been Xcoding with Objective C for a year or so now, but never tried this before. I am interested in HOC, but I've obviously got a lot to learn. Thanks again, John Velman On Tue, Sep 08, 2009 at 08:35:54PM -0400, Ross Mellgren wrote: It sounds like it's looking for the binary package -- you should install it using cabal, e.g. private (per-user) install: cabal update cabal install binary global (system-wide) install: sudo cabal update sudo cabal install --global binary -Ross On Sep 8, 2009, at 7:57 PM, John Velman wrote: I'm unable to build HOC from the svn read-only checkout. Here are some details of what I'm doing. I'm running OS X 10.5.8 on an intel iMac with Xcode is 3.1.3. Haskel and Cabal are from the Haskel platform, haskell-platform-2009.2.0.2-i386.dmg I got Parsec 3.0 from Hackage. I checked out HOC using the svn command at http://code.google.com/p/hoc/source/checkout and checked out revision 411. Configure goes OK except for the complaint: Setup.hs:1:0: Warning: In the use of `defaultUserHooks' (imported from Distribution.Simple): Deprecated: Use simpleUserHooks or autoconfUserHooks, unless you need Cabal-1.2 compatibility in which case you must stick with defaultUserHooks But when I try to build, I get, after a bunch of apparently successful things: --- Loading package binary-0.5.0.1 ... command line: can't load .so/.DLL for: HSbinary-0.5.0.1 (dlopen(libHSbinary-0.5.0.1.dylib, 9): image not found) --- I certainly can't find libHSbinary... of any version on my computer, dylib or not. Tried looking in the /Library/Frameworks/GHC.Framework stuff, also did a find . -iname *libHS* and found libHSGLFW..., libHSparsec-3.0.0. (also tried this in my home directory). What is this, and how do I get it? Best, John Velman ___ 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] Snow Leopard Breaks GHC
My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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] Snow Leopard Breaks GHC
I did a trivial compile and it worked yes (the binary it produced was alright, also). Did the binary it generate have problems, or was it the compilation that failed? -Ross On Aug 28, 2009, at 7:57 PM, David Leimbach wrote: 6.10.4. Did you try to build any binaries? It doesn't produce correct assembly code (it looks like). Dave On Fri, Aug 28, 2009 at 4:55 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: My 6.10.1 install still works alright after upgrade to 10.6/Snow Leopard. What version did you have? -Ross On Aug 28, 2009, at 7:15 PM, David Leimbach wrote: Just thought I'd point out that my old GHC install is now broken by the update to Snow Leopard. Dave ___ 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] Network.Socket error in MacOS 10.5?
I don't think getNameInfo should work for for AF_UNIX -- the name given to SockAddrUnix is a file path, there is no name resolution. From the man page for getnameinfo(3) on OS X: NAME getnameinfo -- socket address structure to hostname and service name ... DESCRIPTION ... The sockaddr structure sa should point to either a sockaddr_in or sockaddr_in6 structure (for IPv4 or IPv6 respectively) that is salen bytes long. Similarly, from the man page for getnameinfo on my linux box: ... The sa argument is a pointer to a generic socket address structure (of type sockaddr_in or sockaddr_in6) of size salen that holds the input IP address and port number. -Ross On Aug 26, 2009, at 2:07 PM, Johan Tibell wrote: On Wed, Aug 26, 2009 at 6:33 PM, kenny luhaskellm...@gmail.com wrote: Hi, I encountered a problem with Network.Socket in MacOS 10.5 Here is the code that I am testing, - - module Main where import qualified Network.Socket as Socket main :: IO () main = do { (hostname, _) - Socket.getNameInfo [] True False (Socket.SockAddrUnix localhost) -- (hostname, _) - Socket.getNameInfo [] True False (Socket.SockAddrInet 9000 (127 + 0 * 256 + 0 * 256^2 + 1 * 256^3)) ; putStrLn (show hostname) } Running the above code yields the following error ghc --make -O2 TestSocket.hs [1 of 1] Compiling Main ( TestSocket.hs, TestSocket.o ) Linking TestSocket ... $ ./TestSocket TestSocket: getNameInfo: does not exist (ai_family not supported) If I switch to SockAddrInet instead, the error is gone. I am using GHC 6.10.3 and Network 2.2.1 Is SockAddrUnix supposed to work on Mac OS X? Could you test it by e.g. writing a small C program that uses it? -- Johan ___ 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] A Question of Restriction
I've seen this expressed with GADTs (which I guess many things can), though I'm not sure if it's the best way, and I'm no type system wizard. If I recall correctly, this use is normally called phantom types. {-# LANGUAGE EmptyDataDecls, GADTs #-} data Even data Odd data Foo a where One :: Foo Odd Two :: Foo Even Three :: Foo Odd Four :: Foo Even Then you can write functions that accept only evens: f :: Foo Even - ... or only odds: f :: Foo Odd - ... or either: f :: Foo a - ... Hope that helps, -Ross On Jul 27, 2009, at 12:01 AM, Brian Troutwine wrote: Hello all. I would like to define a data type that is the super-set of several types and then each of the proper subset types. For example: data Foo = One | Two | Three | Four data Odd = One | Three data Even = Two | Four This, of course, does not work. It seems that such a thing should possible to express entirely in the type system, but I cannot think of how. Would someone be so kind as to explain how this sort of thing can be accomplished? Thanks, Brian ___ 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] YAHT Question about Exercise 4.8
Cons 'a' (Cons 'b' (Cons 'c' Nil)) equivalent to 'a' : ('b' : ('c' : [])) using Haskell's normal list type. -Ross On Jul 25, 2009, at 2:55 AM, Futari wrote: Hi, I was trying to use the solution given, but I don't know how to use it... How do I create something that is of type List? data List a = Nil | Cons a (List a) From the previous examples, I was thinking something like Cons 'a' 'b' 'c' would create a list ['a','b','c'] but it gave me errors... help please, thanks. -- View this message in context: http://www.nabble.com/YAHT-Question-about-Exercise-4.8-tp24655087p24655087.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ 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] A voyage of undiscovery
It's not where -- let also works let { foo Prelude let { foo x = x } in (foo 1, foo True) (1,True) Can you send the code you're trying that doesn't work? -Ross On Jul 16, 2009, at 3:40 PM, Andrew Coppin wrote: Robert Greayer wrote: f0 _ = (foo True, foo 'x') where foo = id is well-typed. Really? That actually works? How interesting... This suggests to me that where-clauses also do strange things to the type system. whereas f1 foo = (foo True, foo 'x') requires 'foo' to be polymorphic in its first argument. This does require a higher rank type, which can't be inferred: You could type f1 as f1 :: (forall a . a - a) - (Bool, Char) and apply it to 'id'. Or you could type it as something like: f1 :: (forall a . a - ()) - ((),()) and apply it to 'const ()' ...all of which is beyond Haskell-98, which is what I am limiting myself to at present. (Actually, even that is a lie. I don't have type-classes yet...) ___ 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] A voyage of undiscovery
Is everything an acceptable answer? -Ross On Jul 16, 2009, at 6:38 PM, Derek Elkins wrote: On Thu, Jul 16, 2009 at 2:52 PM, Andrew Coppinandrewcop...@btinternet.com wrote: Ross Mellgren wrote: It's not where -- let also works Prelude let { foo x = x } in (foo 1, foo True) (1,True) Awesome. So by attempting to implement Haskell's type system, I have discovered that I actually don't understand Haskell's type system. Who'd have thought it? Clearly I must go consult the Report and check precisely what the rules are... The answer to your questions are on the back of this T-shirt. http://www.cafepress.com/skicalc.6225368 ___ 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: Re[2]: [Haskell-cafe] RE: Haskell as a first language?
I agree -- I think the most major learning curve problem (for me) was not learning haskell directly, it was un-learning all those patterns and workarounds and so on from imperative/OOP languages. Of course, the only problem with learning haskell first is that one will probably be mildly annoyed by most of the more common programming languages ;-) -Ross On Jul 14, 2009, at 6:22 AM, Bulat Ziganshin wrote: Hello Michael, Tuesday, July 14, 2009, 2:01:44 PM, you wrote: Haskell is a wonderful language (my favorite language by far) but it is pretty difficult for a beginner. i believe that Haskell is hard for intermediate programmers already knowing any imperative language, but for beginners it should be ideal -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ 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] Circular pure data structures?
Yes, using lazy semantics. http://www.haskell.org/haskellwiki/Tying_the_Knot -Ross On Jul 14, 2009, at 6:27 PM, John Ky wrote: Hello, Is it possible to create a circular pure data structure in Haskell? For example: a :: Data let b = getNext a let c = getNext b c == a -- Gives True Thanks, -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
Re: [Haskell-cafe] How to present the commonness of some objects?
Wordy (and yet technically accurate) names aside, isn't this basically the same thing, except that you must pass the dictionary around by hand? What is the advantage of doing the dictionary passing manually, other than being able to avoid the scoping issue (that requires case) and the slightly odd syntax? I'm not saying you're wrong or anything, I'm just curious on your opinion. To expand your example, would you suggest something like: data Widget = Widget { widgetRun :: IO () } data Label = Label (String - IO ()) data Button = Button (IO ()) labelToWidget = Widget runLabel buttonToWidget = Widget runButton widgetList :: [(Integer, Integer, Widget)] widgetList = [labelToWidget myLabel, buttonToWidget myButton] ? Regarding downcasting, you'd have to use Data.Dynamic or Data.Typeable right? -Ross On Jul 3, 2009, at 3:08 AM, Luke Palmer wrote: On Thu, Jul 2, 2009 at 8:32 PM, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: Wow, this complex Thank you. I will try that. No, don't! There is an easier way. Don't use a class, just use a record. I would translate your class as: data Widget = Widget { widgetRun :: IO () } If you need more capabilities, add them as fields in this record. There is no need for typeclasses here. Keep in mind that with this solution *and* with the ExistentialQuantification solution, there is no possibility of downcasting. I.e. if you were planning on making a GraphicalWidget subclass, and them somewhere seeing if a a Widget is actually a GraphicalWidget, you will be disappointed. The solution in this case is to redesign your software not to need downcasting. This is the point at which you are forced to move away from OO thinking. Luke On Fri, Jul 3, 2009 at 12:24 PM, Ross Mellgrenrmm-hask...@z.odi.ac wrote: You have a couple problems here. The first is that GHC has no idea what particular type 'w' widgetList has, because the empty list is polymorphic. The second is that it looks like you probably want a heterogeneous list of widgets -- that is, possibly different types of widget as long as they all conform to Widget. To do this you'll need ExistentialQuantification (or GADTs I guess?). For example: {-# LANGUAGE ExistentialQuantification #-} class Widget w where widgetRun :: w - IO () data SomeWidget = forall w. Widget w = SomeWidget w widgetList :: [(Integer, Integer, SomeWidget)] widgetList = [] main = mapM aux widgetList aux (x, y, sw) = case sw of SomeWidget w - widgetRun w Note that the type variable for widgetList 'w' has disappeared. Before, with the type variable 'w', all elements of the widgetList had to be of the same type (lists being homogeneous). By wrapping up the type variable 'w' inside SomeWidget, you can now have whatever types of widgets in that SomeWidget, e.g. data Button = Button (IO ()) instance Widget Button where widgetRun = ... data Label = Label (String - IO ()) instance Widget Label where widgetRun = ... widgetList:: [(Integer, Integer, SomeWidget)] widgetList = [ SomeWidget (Button $ putStrLn ding!) , SomeWidget (Label $ putStrLn . (entered: ++)) ] Before, without existential quantification, you had to have all the same type of widget (e.g. all Button or all Label) Hope this makes it more clear. -Ross On Jul 3, 2009, at 12:00 AM, Magicloud Magiclouds wrote: Hi, I thought class was for this purpose. But it turns out not. Code as following could not compiled. 1 main = do 2 mapM_ (\(x, y, widget) - do 3a - widgetRun widget 4putStrLn $ show a 5 ) widgetList 6 7 widgetList :: (Widget w) = [(Integer, Integer, w)] 8 widgetList = [] 9 10 class Widget w where 11 widgetRun :: w - IO () --- % ghc --make tmp/test.hs [1 of 1] Compiling Main ( tmp/test.hs, /tmp/Main.o ) tmp/test.hs:3:16: Ambiguous type variable `t' in the constraint: `Widget t' arising from a use of `widgetRun' at tmp/test.hs: 3:16-31 Probable fix: add a type signature that fixes these type variable(s) -- 竹密岂妨流水过 山高哪阻野云飞 ___ 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
Re: [Haskell-cafe] How to present the commonness of some objects?
You have a couple problems here. The first is that GHC has no idea what particular type 'w' widgetList has, because the empty list is polymorphic. The second is that it looks like you probably want a heterogeneous list of widgets -- that is, possibly different types of widget as long as they all conform to Widget. To do this you'll need ExistentialQuantification (or GADTs I guess?). For example: {-# LANGUAGE ExistentialQuantification #-} class Widget w where widgetRun :: w - IO () data SomeWidget = forall w. Widget w = SomeWidget w widgetList :: [(Integer, Integer, SomeWidget)] widgetList = [] main = mapM aux widgetList aux (x, y, sw) = case sw of SomeWidget w - widgetRun w Note that the type variable for widgetList 'w' has disappeared. Before, with the type variable 'w', all elements of the widgetList had to be of the same type (lists being homogeneous). By wrapping up the type variable 'w' inside SomeWidget, you can now have whatever types of widgets in that SomeWidget, e.g. data Button = Button (IO ()) instance Widget Button where widgetRun = ... data Label = Label (String - IO ()) instance Widget Label where widgetRun = ... widgetList:: [(Integer, Integer, SomeWidget)] widgetList = [ SomeWidget (Button $ putStrLn ding!) , SomeWidget (Label $ putStrLn . (entered: ++)) ] Before, without existential quantification, you had to have all the same type of widget (e.g. all Button or all Label) Hope this makes it more clear. -Ross On Jul 3, 2009, at 12:00 AM, Magicloud Magiclouds wrote: Hi, I thought class was for this purpose. But it turns out not. Code as following could not compiled. 1 main = do 2 mapM_ (\(x, y, widget) - do 3a - widgetRun widget 4putStrLn $ show a 5 ) widgetList 6 7 widgetList :: (Widget w) = [(Integer, Integer, w)] 8 widgetList = [] 9 10 class Widget w where 11 widgetRun :: w - IO () --- % ghc --make tmp/test.hs [1 of 1] Compiling Main ( tmp/test.hs, /tmp/Main.o ) tmp/test.hs:3:16: Ambiguous type variable `t' in the constraint: `Widget t' arising from a use of `widgetRun' at tmp/test.hs: 3:16-31 Probable fix: add a type signature that fixes these type variable(s) -- 竹密岂妨流水过 山高哪阻野云飞 ___ 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] Cabal fun [Half-integer]
I presume that many of the developers do not have windows machines (presumably because windows sucks). Maybe you could help them by trying to track down where the error in the code is, and even better yet submitting a patch? This is all free by the virtue of people giving what time they can, and if you don't happen to have a windows box to test on, it can be very hard to provide compatibility for it. Same in the reverse direction. -Ross On Jun 29, 2009, at 3:55 PM, Andrew Coppin wrote: Jason Dagit wrote: On Mon, Jun 29, 2009 at 11:57 AM, Andrew Coppin andrewcop...@btinternet.com mailto:andrewcop...@btinternet.com wrote: Rather less fortunately, it still doesn't actually fix my problem: E:\Haskell\AOC-HalfIntegercabal configure Resolving dependencies... Configuring AOC-HalfInteger-1.0... E:\Haskell\AOC-HalfIntegercabal sdist Building source dist for AOC-HalfInteger-1.0... Preprocessing library AOC-HalfInteger-1.0... Source tarball created: dist\AOC-HalfInteger-1.0.tar.gz cabal: dist\src\sdist.1288\AOC-HalfInteger-1.0\Data\HalfInteger.hs: removeFile: permission denied (Permission denied) I have no idea what the hell it's upset about now... I've now been trying to create this damned tarball since 5PM yesterday, and I still haven't managed it. At this point I'm losing the will to continue with this crazy project. Clearly this is way too much effort to expend just to upload 50 lines of code. I can't say for certain, but just reading the output it looks like it created a tarball in a temporary folder (that worked) and then when it tried to clean it up it failed. Sounds like a bug report is in order. So, yet again, it appears I'm the first poor soul to try using this on Windows. The very first time I tried to use Gtk2hs, the installer for Windows was trivially broken. In fairness, Duncan fixed this within an hour or two of me pointing out the problem. But the fact remains: It had been out for a week, and I was the *only* person to have tried to use it on Windows. (Or possibly the only person to actually complain, rather than just give up.) Don kept telling me about some cool Core syntax hilighter he wrote, so I went to all the trouble of downloading it, downloading and building all of its dependencies, only to discover oh, by the way, it only works on Linux. A while back Cabal had a bug where (on Windows only) it couldn't find ld or something daft. [Again, fortunately that one got corrected - eventually - in the next GHC release.] I try to run sdist, and discover that that's broken on Windows too. But don't worry, there's a replacement tool... which is also broken on Windows... This is an exercise in pure frustration! Sometimes it seems as if *everything* is broken on Windows. Hmm... I'm just ranting now. One presumes that when they fixed cabal sdist to work on Windows, at least one person checked that it did, in fact, work. That would mean it got broken again at some point after this. Maybe I just need to find an older version or something... And after that... I guess I create *another* account on *another* bug tracker and submit *another* hey, this is broken on Windows ticket... ___ 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] Type system trickery
I'm no expert, but it seems like those constructors should return Foobar NoZoo, unless you're nesting so there could be a Zoo, in which case the type variable a should transit, for example: data Foobar a where Foo :: X - Y - Foobar NoZoo Bar :: X - Y - Foobar NoZoo Baz :: Foobar a - Foobar a Zoo :: Foobar NoZoo - Foobar Zoo value = Zoo $ Foo (X 1) (Y 'a') value2 = Zoo $ Baz $ Foo (X 1) (Y 'a') -- value3 = Zoo $ Baz $ Zoo $ Foo (X 1) (Y 'a') --Couldn't match expected type `NoZoo' against inferred type `Zoo' -- Expected type: Foobar NoZoo -- Inferred type: Foobar Zoo --In the second argument of `($)', namely --`Baz $ Zoo $ Foo (X 1) (Y 'a')' --In the expression: Zoo $ Baz $ Zoo $ Foo (X 1) (Y 'a') That is, if you construct a Baz with something else that doesn't have a Zoo (e.g. NoZoo) then the resultant type is also NoZoo. The converse is true. Why would you want it to generate a polymorphic Foobar when it definitely is NoZoo? -Ross (p.s. the example names in this thread are a bit ridiculous ;-) ) On Jun 23, 2009, at 4:01 PM, Andrew Coppin wrote: Ross Mellgren wrote: This works for me: {-# LANGUAGE EmptyDataDecls, GADTs #-} module Main where data NoZoo data Zoo newtype X = X Int deriving (Show) newtype Y = Y Char deriving (Show) data Foobar a where Foo :: X - Y - Foobar NoZoo Bar :: X - Y - Foobar NoZoo Zoo :: Foobar NoZoo - Foobar Zoo foobar :: Foobar a - X foobar f = case f of Foo x _ - x Zoo g - foobar g main :: IO () main = putStrLn . show $ foobar (Zoo $ Foo (X 1) (Y 'a')) Could you post a test case? Thinking about this more carefully, I started out with data Foobar a where Foo :: X - Y - Foobar a Zoo :: Foobar a - Foobar Zoo which is no good, because Zoo can be nested arbitrarily deep. So I tried to change it to data Foobar a where Foo :: X - Y - Foobar NoZoo Zoo :: Foobar NoZoo - Foobar Zoo But *actually*, changing the second type signature only is sufficient. Indeed, it turns out I don't *want* to change the first one. I want to use the type system to track whether Zoo may or may not be present, not whether it is or is not present. In other words, I want Foobar Zoo to mean that there *might* be a Zoo in there, but there isn't guaranteed to be one. But I want Foobar NoZoo to be guaranteed not to contain Zoo. So anyway... my program now uses GADTs, I've spent ages chasing down all the typechecker errors (and, inevitably, in some places clarifying what the code is actually supposed to do), and my program now typechecks and does what it did before, except with slightly more type safety. (In particular, I've deleted several calls to error now, because those case alternatives can never occur). Thanks to all the people for your help! :-D ___ 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] Type system trickery
This works for me: {-# LANGUAGE EmptyDataDecls, GADTs #-} module Main where data NoZoo data Zoo newtype X = X Int deriving (Show) newtype Y = Y Char deriving (Show) data Foobar a where Foo :: X - Y - Foobar NoZoo Bar :: X - Y - Foobar NoZoo Zoo :: Foobar NoZoo - Foobar Zoo foobar :: Foobar a - X foobar f = case f of Foo x _ - x Zoo g - foobar g main :: IO () main = putStrLn . show $ foobar (Zoo $ Foo (X 1) (Y 'a')) Could you post a test case? On Jun 22, 2009, at 3:34 PM, Andrew Coppin wrote: Niklas Broberg wrote: Not nearly as annoying as this: data Foobar a where Foo :: X - Y - Foobar NoZoo Bar :: X - Y - Foobar NoZoo Zoo :: Foobar NoZoo - Foobar Zoo For some reason, if I do this I get endless type check errors. I have to change the top two back to Foobar a before it will work. *sigh* Well, that means something very different obviously. It means Zoo constructors can never take Zoo arguments. ...which would be precisely what I want, yes. :-) Why would that give you type check errors? If it does, you're doing something else wrong. I think (I'm not sure) it's because of stuff like this: foobar :: Foobar a - X foobar f = case f of Foo x y - ... Zoo g - foobar g The first case implies that f :: Foobar NoZoo, while the second implies that f :: Foobar Zoo. Apparently this seemingly reasonable construct does not type-check... ___ 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] Obscure weirdness
Really, without code or more than it just disappears, it's just conjecture what's happening. Can you post the code, or even better yet a minimized case that reproduces it? -Ross On Jun 20, 2009, at 1:34 PM, Andrew Coppin wrote: Alexander Dunlap wrote: On Sat, Jun 20, 2009 at 8:29 AM, Andrew Coppin andrewcop...@btinternet.com wrote: OK, so here's an interesting problem... I've been coding away all day, but now my program is doing something slightly weird. For a specific input, it summarily terminates. The registered exception handler does not fire. There is no output to stdout or stderr indicating what the problem is. It just *stops* half way through the printout. Weirder: If I run it in GHCi, then GHCi itself terminates. (I didn't think you could *do* that!) I think you'll need to provide a bit more detail about what you're doing in order for anyone to have anything to go off of. If you can link to the source, that would help, or even give a summary of what you're trying to do. The program takes some text, parses it as a lambda calculus expression, and prints it out again. Except, somewhere during the variable uniqueness pass, the program just halts. For no defined reason. As you can see, nothing remotely unusual for a Haskell program to be doing. And yet, the result is very unusual. (I.e., halting part-way through some pure code without throwing an exception.) Given that it doesn't appear to be a known bug (presumably somebody would have said something by now if it was...), I think I'm going to try upgrading GHC anyway, just for arguments' sake, and see if that fixes it. ___ 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] IORef memory leak
It looks offhand like you're not being strict enough when you put things back in the IORef, and so it's building up thunks of (+1)... With two slight mods: go 0 = return () go n = do modifyIORef ior (+1) go (n-1) -- go 0 = return () go n = do modifyIORef ior (\ x - let x' = x+1 in x `seq` x') go (n-1) and go n = do x - readIORef ior writeIORef ior (x+1) go (n-1) -- go n = do x - readIORef ior writeIORef ior $! x+1 go (n-1) It runs much better (with loop count = 10,000,000) -- leak1 is the code you posted, leak2 is with these changes: r...@hugo:~$ ./leak1 +RTS -s ./leak1 +RTS -s 200,296,364 bytes allocated in the heap 365,950,896 bytes copied during GC 66,276,472 bytes maximum residency (7 sample(s)) 1,906,448 bytes maximum slop 131 MB total memory in use (1 MB lost due to fragmentation) snip %GC time 75.9% (79.2% elapsed) Alloc rate977,656,335 bytes per MUT second Productivity 24.0% of total user, 20.5% of total elapsed r...@hugo:~$ ./leak2 +RTS -s ./leak2 +RTS -s 160,006,032 bytes allocated in the heap 11,720 bytes copied during GC 1,452 bytes maximum residency (1 sample(s)) 9,480 bytes maximum slop 1 MB total memory in use (0 MB lost due to fragmentation) snip %GC time 0.5% (0.8% elapsed) Alloc rate626,590,037 bytes per MUT second Productivity 99.2% of total user, 97.8% of total elapsed -Ross On Jun 18, 2009, at 10:46 PM, Jim Snow wrote: I'm having some trouble with excessive memory use in a program that uses a lot of IORefs. I was able to write a much simpler program which exhibits the same sort of behavior. It appears that modifyIORef and writeIORef leak memory; perhaps they keep a reference to the old value. I tried both ghc-6.8.3 and ghc-6.10.1. Is this a known limitation, or is this a ghc bug, or am I using IORefs in the wrong way? -jim module Main where import Data.IORef import Control.Monad -- Leaks memory leakcheck1 ior = do go 10 where go 0 = return () go n = do modifyIORef ior (+1) go (n-1) -- Leaks memory leakcheck2 ior = do go 10 where go 0 = return () go n = do x - readIORef ior writeIORef ior (x+1) go (n-1) -- Runs in constant memory leakcheck3 ior = do go 10 where go 0 = return () go n = do x - readIORef ior go (n-1) main :: IO () main = do ior - newIORef 0 leakcheck2 ior compiled with: ghc -O2 --make Leak.hs -o Leak ___ 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] IORef memory leak
D'oh, yeah that is better. You know, I actually had that and had expanded it because I was going to seq both the input and the result of the (+1), but punted on it and didn't switch back to the more compact format. -Ross On Jun 19, 2009, at 12:45 AM, Luke Palmer wrote: On Thu, Jun 18, 2009 at 9:55 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: It looks offhand like you're not being strict enough when you put things back in the IORef, and so it's building up thunks of (+1)... With two slight mods: go 0 = return () go n = do modifyIORef ior (+1) go (n-1) -- go 0 = return () go n = do modifyIORef ior (\ x - let x' = x+1 in x `seq` x') go (n-1) Just a slight prettification of that line: modifyIORef ior ((1+) $!) Or applied prefix if you prefer. Prefix ($!) has the nice interpretation as the HOF that makes its argument into a strict function. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Need some help with an infinite list
Here's a way using list comprehensions: Prelude Data.List take 1000 $ concat.concat $ [ [ replicate n c | c - ['a'..'z'] ] | n - [1..] ] abcdefghijklmnopqrstuvwxyzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvw wxxyyzzaaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzzabcdefghijklmnopqrstuvwxyzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzzabcdefgh -Ross On Jun 16, 2009, at 8:39 PM, Daniel Peebles wrote: One (rather ugly) option is: tail . map (\y - showIntAtBase 26 (\x - chr (x + 96)) y ) $ [0..] but I'm sure there's a prettier one out there :) On Tue, Jun 16, 2009 at 8:28 PM, GüŸnther Schmidtgue.schm...@web.de wrote: Hi guys, I'd like to generate an infinite list, like [a, b, c .. z, aa, ab, ac .. az, ba, bb, bc .. bz, ca ...] When I had set out to do this I thought, oh yeah no prob, in a heartbeat. Uhm. Help, pls! Günther PS: I know this should be a no-brainer, sry ___ 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
Re: [Haskell-cafe] Re: Need some help with an infinite list
Oh sorry about that, misread the problem. -Ross On Jun 16, 2009, at 9:16 PM, Günther Schmidt wrote: Dear Ross, thanks for your post, you got it almost right, I needed something like aa, ab, ac ... It seems that Thomas has figured it out. Günther ___ 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] Cabal addressibility problem
If your module statements say Swish in them, e.g. module Swish.HaskellUtils.TestHelpers where then you should probably have no hs-source-dirs (or hs-source-dirs: .) and then use Swish.HaskellUtils.TestHelpers. But leave Main-Is: as you have it. -Ross On Jun 5, 2009, at 4:49 PM, Vasili I. Galchin wrote: getting farther . Executable GraphPartitionTest Hs-source-dirs: Swish/ added this Main-Is:HaskellRDF/GraphPartitionTest.hschanged to a real filesystem path Other-modules: HaskellRDF.GraphPartition HaskellRDF.GraphClass HaskellUtils.ListHelpers HaskellUtils.TestHelpers now says can't find module 'Swish.HaskellUtils.TestHelpers'??? Vasili On Fri, Jun 5, 2009 at 3:28 PM, Gwern Branwen gwe...@gmail.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On Fri, Jun 5, 2009 at 4:10 PM, Vasili I. Galchin wrote: for directory structure I Swish-0.2.1/Swish/HaskellRDF and Swish-0.2.1/Swish/HaskellUtils ... there are deeper directories but that distract from the discussion ... to make things concete: 1) swish.cabal is directly under Swish-0.2.1 2) GraphPartitionTest.hs is under Swish-0.2.1/Swish/HaskellRDF 3) GraphPartitionTest's dependencies are either under HaskellRDF or HaskellUtils Hope this helps to make things clearer. I added a Hs-source-dirs but that help. I did a ruinhaskell Setup -? to check on options. I don't see any verbose mode so that when I do runhaskell Setup build I can moniitor the progress of my build for diagnostic purposes! Is there a verbose mode? Thanks, Vasili [04:27 PM] 0Mb$ build --help Usage: Setup build [FLAGS] Flags for build: -h --help Show this help text -v --verbose[=n] Control verbosity (n is 0--3, default verbosity level is 1) --builddir=DIR The directory where Cabal puts generated build files (default dist) --with-PROG=PATHgive the path to PROG --PROG-options=OPTS give extra options to PROG --PROG-option=OPT give an extra option to PROG (no need to quote options containing spaces) - -- gwern -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEAREKAAYFAkopf/sACgkQvpDo5Pfl1oIZfgCeInjWOqdxejdpsBaI62YHkSHu BvIAn1ZsC9rCYmluCW2UCmFGVFcAw3bh =S6In -END PGP SIGNATURE- ___ 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] type checking that I can't figure out ...
You've applied two solutions to get the value out -- pattern matching (Just reinfo) and fromJust. You should use one or the other, but not both: -- pattern matching remLookupFwd :: (ReVars m t) = SimplRe t - ReM m t (ReInfo t) remLookupFwd re = do fwd - gets resFwdMap let { Just reinfo = M.lookup re fwd }-- PROBLEM return reinfo -- fromJust remLookupFwd :: (ReVars m t) = SimplRe t - ReM m t (ReInfo t) remLookupFwd re = do fwd - gets resFwdMap let { reinfo = fromJust (M.lookup re fwd) }-- PROBLEM return reinfo BTW, I would personally write this as one line (untested) gets (fromJust . M.lookup re . resFwdMap) -Ross On Jun 3, 2009, at 1:18 PM, Vasili I. Galchin wrote: Hi Andrew (Bromage), I reversed the parameter order to Data.Map.lookup and calling fromJust to pull out value from Maybe wrapper ... all as you suggested: remLookupFwd :: (ReVars m t) = SimplRe t - ReM m t (ReInfo t) remLookupFwd re = do fwd - gets resFwdMap let { Just reinfo = fromJust(M.lookup re fwd) }-- PROBLEM return reinfo I am still getting a type mismatch: Swish\HaskellRDF\Dfa\Dfa.lhs:162:29: Couldn't match expected type `Maybe t' against inferred type `ReInfo t1' In the expression: fromJust (M.lookup re fwd) In a pattern binding: Just reinfo = fromJust (M.lookup re fwd) In the expression: do fwd - gets resFwdMap let Just reinfo = fromJust (M.lookup re fwd) return reinfo Vasili ___ 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] comprehension problem
P Float is the constructor to create a value of this type, similar to data declarations. That is, 0.5 :: Float, P 0.5 :: Probability The {} notation after D creates a record accessor, also similar to data declarations. It's equivalent to making an unD that unwraps the value yourself: newtype Dist a = D { unD :: [(a, Probability)] } is the same as newtype Dist a = D [(a, Probability)] unD :: Dist a - [(a, Probability)] unD (D x) = x a in Dist a is a type variable, for example you could have Dist Float (containing [(Float, Probability)]), or Dist String (containing [(String, Probability)]) -Ross On Jun 3, 2009, at 4:01 PM, ptrash wrote: Hi, what does this to code rows mean: newtype Probability = P Float newtype Dist a = D {unD :: [(a, Probability)]} newtype definies a new type called Probability. But what does P Float mean? And what is the a in Dist a? What does D {...} mean? Thanks for your help. -- View this message in context: http://www.nabble.com/comprehension-problem-tp23858359p23858359.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ 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] type checking that I can't figure out ...
True, so perhaps better written as: import Data.Maybe (fromMaybe) gets (fromMaybe (error could not find re in resFwdMap) . M.lookup re . resFwdMap) with more detail in error message as appropriate. -Ross On Jun 3, 2009, at 5:57 PM, Henning Thielemann wrote: Ross Mellgren schrieb: You've applied two solutions to get the value out -- pattern matching (Just reinfo) and fromJust. You should use one or the other, but not both: -- pattern matching remLookupFwd :: (ReVars m t) = SimplRe t - ReM m t (ReInfo t) remLookupFwd re = do fwd - gets resFwdMap let { Just reinfo = M.lookup re fwd }-- PROBLEM return reinfo -- fromJust remLookupFwd :: (ReVars m t) = SimplRe t - ReM m t (ReInfo t) remLookupFwd re = do fwd - gets resFwdMap let { reinfo = fromJust (M.lookup re fwd) } -- PROBLEM return reinfo BTW, I would personally write this as one line (untested) gets (fromJust . M.lookup re . resFwdMap) fromJust should be avoided, since it is partial and if it results in an error, the error message points to the implementation of fromJust, not its application. Pattern matching is better, but 'maybe' and 'fromMaybe' are best. ___ 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] Missing a Deriving?
mplus is a method of class MonadPlus, so you need to write it in a separate instance from the one for Monad, e.g. instance MonadPlus Failable where mplus = ... -Ross On Jun 1, 2009, at 9:28 PM, michael rice wrote: Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es -Inline Attachment Follows- ___ 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
Re: [Haskell-cafe] Missing a Deriving?
Oh I wasn't clear -- you need multiple instance declarations for a given type (Failable, for example), one for each type class you're implementing. That is, instance Monad Failable where return = ... ... instance MonadPlus Failable where mplus = ... ... -Ross On Jun 1, 2009, at 9:40 PM, michael rice wrote: Hi Ross, I thought of that, but return, fail, and = became not visible when I changed the instance declaration from Monad to MonadPlus.. Can Failable be in two instance declarations, one for Monad (giving it return, fail, and =) and one for MonadPlus (giving it mplus)? Michael --- On Mon, 6/1/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Missing a Deriving? To: michael rice nowg...@yahoo.com Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Monday, June 1, 2009, 9:33 PM mplus is a method of class MonadPlus, so you need to write it in a separate instance from the one for Monad, e.g. instance MonadPlus Failable where mplus = ... -Ross On Jun 1, 2009, at 9:28 PM, michael rice wrote: Still stumped. Maybe and [] are in the same MonadPlus monad, but how do I make monad Failable understand mplus? I'm now getting this error upon loading: Prelude :l graph5 [1 of 1] Compiling Main ( graph5.hs, interpreted ) graph5.hs:36:4: `mplus' is not a (visible) method of class `Monad' Failed, modules loaded: none. Prelude Complete code follows. Michael = import Monad data Failable a = Success a | Fail String deriving (Show) data Graph v e = Graph [(Int,v)] [(Int,Int,e)] {- class Computation c where success :: a - c a failure :: String - c a augment :: c a - (a - c b) - c b combine :: c a - c a - c a instance Computation Maybe where success = Just failure = const Nothing augment (Just x) f = f x augment Nothing _ = Nothing combine Nothing y = y combine x _ = x instance Computation Failable where success = Success failure = Fail augment (Success x) f = f x augment (Fail s) _ = Fail s combine (Fail _) y = y combine x _ = x -} instance Monad Failable where return = Success fail = Fail (=) (Success x) f = f x (=) (Fail s) _ = Fail s mplus (Fail _) y = y mplus x _ = x {- instance Computation [] where success a = [a] failure = const [] augment l f = concat (map f l) combine = (++) searchAll g@(Graph vl el) src dst | src == dst = success [src] | otherwise = search' el where search' [] = failure no path search' ((u,v,_):es) | src == u = (searchAll g v dst `augment` (success . (u:))) `combine` search' es | otherwise = search' es -} searchAll g@(Graph vl el) src dst | src == dst = return [src] | otherwise = search' el where search' [] = fail no path search' ((u,v,_):es) | src == u = (searchAll g v dst = (return . (u:))) `mplus` search' es | otherwise = search' es -Inline Attachment Follows- ___ 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
Re: [Haskell-cafe] Random number example
I'm not sure what you're asking by define type Random [Int]? Your type Random a will allow a to be any type, e.g. [Int] is perfectly fine. If what you're asking is how do you get from Random Int to Random [Int], the usual answer would be to use replicateM :: Monad m = Int - m a - m [a] which is formulated from replicate :: Int - a - [a] and sequence :: Monad m = [m a] - m [a] of course, you're implementing Monad all over again without using the Monad typeclass, so you can't use the library functions pertaining to monads. In your case, I'd build it up the same way the library does it -- create a list of actions, and then use a function to bind all the actions together, e.g. rolls :: Int - [Random Int] rolls n = replicate n rollDie and then create something that binds them together, usually a foldr, so you could use it like this: sequenceRandom :: [Random a] - Random [a] sequenceRandom = ... rollNDice :: Int - Random [Int] rollNDice = sequenceRandom . rolls -Ross On Apr 26, 2009, at 8:45 PM, michael rice wrote: How do I define type Random [Int] for rollNDice in Exercise 1, given the code below? Michael Exercises 1. Implement rollNDice :: Int - Random [Int] from the previous subsection with = and return. NOTE: Since = and return are already present in the Prelude, you may want to use import Prelude hiding ((=),return) to avoid compilation errors. = {-# LANGUAGE NoImplicitPrelude #-} import Prelude hiding ((), (=), return) type Seed = Int type Random a = Seed - (a, Seed) randomNext :: Seed - Seed randomNext rand = if newRand 0 then newRand else newRand + 2147483647 where newRand = 16807 * lo - 2836 * hi (hi,lo) = rand `divMod` 127773 rollDie :: Random Int rollDie seed = ((seed `mod` 6) + 1, randomNext seed) () :: Random a - Random b - Random b () m n = \seed0 - let (result1, seed1) = m seed0 (result2, seed2) = n seed1 in (result2, seed2) (=) :: Random a - (a - Random b) - Random b (=) m g = \seed0 - let (result1, seed1) = m seed0 (result2, seed2) = (g result1) seed1 in (result2, seed2) return :: a - Random a return x = \seed0 - (x, seed0) sumTwoDice :: Random Int sumTwoDice = rollDie = (\die1 - rollDie = (\die2 - return (die1 + die2))) rollNDice :: Int - Random [Int] --- On Thu, 4/23/09, michael rice nowg...@yahoo.com wrote: From: michael rice nowg...@yahoo.com Subject: Re: [Haskell-cafe] Random number example To: Ross Mellgren rmm-hask...@z.odi.ac Cc: haskell-cafe@haskell.org Date: Thursday, April 23, 2009, 5:49 PM Hi Ross, Thanks for going the extra mile. A lot of what you did I haven't seen before, so it's going to take me some time to go through it. But I'll be back. Michael --- On Thu, 4/23/09, Ross Mellgren rmm-hask...@z.odi.ac wrote: From: Ross Mellgren rmm-hask...@z.odi.ac Subject: Re: [Haskell-cafe] Random number example To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, April 23, 2009, 11:51 AM So there are a couple problems. First is you are trying to rebind prelude functions, when instead you should be creating an instance of Monad. This requires a bit of shuffling because without language extensions you can't instance Monad Random for your type of Random, as it is a type synonym. So, changing the type synonym to a newtype and instancing monad, you get: module Rand9b where import Control.Applicative (Applicative(..), ($), (*)) import Control.Monad (ap, liftM) type Seed = Int newtype Random a = Rand { unRand :: (Seed - (a, Seed)) } randomNext :: Seed - Seed randomNext rand = if newRand 0 then newRand else newRand + 2147483647 where newRand = 16807 * lo - 2836 * hi (hi,lo) = rand `divMod` 127773 rollDie :: Random Int rollDie = Rand $ \ seed - ((seed `mod` 6) + 1, randomNext seed) instance Monad Random where (=) = randomBind return = randomReturn instance Functor Random where fmap = liftM instance Applicative Random where pure = return (*) = ap randomBind :: Random a - (a - Random b) - Random b m `randomBind` g = Rand $ \seed0 - let (result1, seed1) = unRand m $ seed0 (result2, seed2) = unRand (g result1) $ seed1 in (result2, seed2) randomReturn :: a - Random a randomReturn x = Rand $ \ seed0 - (x, seed0) sumTwoDice :: Random Int sumTwoDice = (+) $ rollDie * rollDie I also threw in instances of Functor and Applicative, so that I could simplify sumTwoDice using applicative form (much nicer, no? Applicative is totally rockin') Now you need one more thing, a way to convert a series of Random actions into a pure function: runRandom :: Seed - Random a - a runRandom s f = fst . unRand f $ s which now makes what you want to do in GHCi easy and well wrapped: Prelude :reload [1 of 1] Compiling Rand9b ( rand9b.hs, interpreted ) Ok, modules loaded: Rand9b. *Rand9b runRandom 0 sumTwoDice 3 Hope this helps, -Ross On Apr 23, 2009, at 11:28 AM
Re: [Haskell-cafe] Re: Overriding a Prelude function?
Hahah yeah of course, I left it implicit that you'd only do this if you were changing the types (e.g. parameterized monads or what have you) -Ross On Apr 23, 2009, at 5:15 AM, Heinrich Apfelmus wrote: Ross Mellgren wrote: True enough -- if you really want to redefine the monadic operator, you have to use {-# LANGUAGE NoImplicitPrelude #-} import Prelude hiding ((), (=), return) or something like it, although Michael's example didn't appear to be going quite that far. Or just make it an instance of Monad . :D Regards, apfelmus -- http://apfelmus.nfshost.com ___ 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] Random number example
So there are a couple problems. First is you are trying to rebind prelude functions, when instead you should be creating an instance of Monad. This requires a bit of shuffling because without language extensions you can't instance Monad Random for your type of Random, as it is a type synonym. So, changing the type synonym to a newtype and instancing monad, you get: module Rand9b where import Control.Applicative (Applicative(..), ($), (*)) import Control.Monad (ap, liftM) type Seed = Int newtype Random a = Rand { unRand :: (Seed - (a, Seed)) } randomNext :: Seed - Seed randomNext rand = if newRand 0 then newRand else newRand + 2147483647 where newRand = 16807 * lo - 2836 * hi (hi,lo) = rand `divMod` 127773 rollDie :: Random Int rollDie = Rand $ \ seed - ((seed `mod` 6) + 1, randomNext seed) instance Monad Random where (=) = randomBind return = randomReturn instance Functor Random where fmap = liftM instance Applicative Random where pure = return (*) = ap randomBind :: Random a - (a - Random b) - Random b m `randomBind` g = Rand $ \seed0 - let (result1, seed1) = unRand m $ seed0 (result2, seed2) = unRand (g result1) $ seed1 in (result2, seed2) randomReturn :: a - Random a randomReturn x = Rand $ \ seed0 - (x, seed0) sumTwoDice :: Random Int sumTwoDice = (+) $ rollDie * rollDie I also threw in instances of Functor and Applicative, so that I could simplify sumTwoDice using applicative form (much nicer, no? Applicative is totally rockin') Now you need one more thing, a way to convert a series of Random actions into a pure function: runRandom :: Seed - Random a - a runRandom s f = fst . unRand f $ s which now makes what you want to do in GHCi easy and well wrapped: Prelude :reload [1 of 1] Compiling Rand9b ( rand9b.hs, interpreted ) Ok, modules loaded: Rand9b. *Rand9b runRandom 0 sumTwoDice 3 Hope this helps, -Ross On Apr 23, 2009, at 11:28 AM, michael rice wrote: I pretty much followed the sequence of steps that led to this final code (see below), but will be looking it over for a while to make sure it sinks in. In the meantime, I get this when I try to use it (sumTwoDice) at the command line: [mich...@localhost ~]$ ghci rand9 GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( rand9.hs, interpreted ) Ok, modules loaded: Main. *Main sumTwoDice interactive:1:0: No instance for (Show (Seed - (Int, Seed))) arising from a use of `print' at interactive:1:0-9 Possible fix: add an instance declaration for (Show (Seed - (Int, Seed))) In a stmt of a 'do' expression: print it *Main Can I employ a 'do' expression from the command line? Also, can I now use functions () (=) and 'return' defined in the Prelude and still have this code work? Michael == {-# LANGUAGE NoImplicitPrelude #-} import Prelude hiding ((), (=), return) type Seed = Int type Random a = Seed - (a, Seed) randomNext :: Seed - Seed randomNext rand = if newRand 0 then newRand else newRand + 2147483647 where newRand = 16807 * lo - 2836 * hi (hi,lo) = rand `divMod` 127773 rollDie :: Random Int rollDie seed = ((seed `mod` 6) + 1, randomNext seed) () :: Random a - Random b - Random b () m n = \seed0 - let (result1, seed1) = m seed0 (result2, seed2) = n seed1 in (result2, seed2) (=) :: Random a - (a - Random b) - Random b (=) m g = \seed0 - let (result1, seed1) = m seed0 (result2, seed2) = (g result1) seed1 in (result2, seed2) return :: a - Random a return x = \seed0 - (x, seed0) sumTwoDice :: Random Int sumTwoDice = rollDie = (\die1 - rollDie = (\die2 - return (die1 + die2))) ___ 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] Overriding a Prelude function?
I think import Prelude hiding (()) does that. -Ross On Apr 22, 2009, at 11:44 AM, michael rice wrote: I've been working through this example from: http://en.wikibooks.org/wiki/Haskell/Understanding_monads I understand what they're doing all the way up to the definition of (), which duplicates Prelude function (). To continue following the example, I need to know how to override the Prelude () with the () definition in my file rand.hs. Michael == [mich...@localhost ~]$ cat rand.hs import System.Random type Seed = Int randomNext :: Seed - Seed randomNext rand = if newRand 0 then newRand else newRand + 2147483647 where newRand = 16807 * lo - 2836 * hi (hi,lo) = rand `divMod` 127773 toDieRoll :: Seed - Int toDieRoll seed = (seed `mod` 6) + 1 rollDie :: Seed - (Int, Seed) rollDie seed = ((seed `mod` 6) + 1, randomNext seed) sumTwoDice :: Seed - (Int, Seed) sumTwoDice seed0 = let (die1, seed1) = rollDie seed0 (die2, seed2) = rollDie seed1 in (die1 + die2, seed2) () m n = \seed0 - let (result1, seed1) = m seed0 (result2, seed2) = n seed1 in (result2, seed2) [mich...@localhost ~]$ ___ 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] Overriding a Prelude function?
True enough -- if you really want to redefine the monadic operator, you have to use {-# LANGUAGE NoImplicitPrelude #-} import Prelude hiding ((), (=), return) or something like it, although Michael's example didn't appear to be going quite that far. -Ross On Apr 22, 2009, at 12:37 PM, Dan Weston wrote: Be aware that the do unsugars to (Prelude.), not your (), even if you hide (Prelude.): import Prelude hiding (()) m f = error Call me! main = putStrLn . show $ do [3,4] [5] The desugaring of the do { [3,4]; [5] } is (Prelude.) [3,4] [5] = [5,5], whereas you might have hoped for [3,4] [5] = error Call me! Dan Ross Mellgren wrote: I think import Prelude hiding (()) does that. -Ross On Apr 22, 2009, at 11:44 AM, michael rice wrote: I've been working through this example from: http://en.wikibooks.org/wiki/Haskell/Understanding_monads I understand what they're doing all the way up to the definition of (), which duplicates Prelude function (). To continue following the example, I need to know how to override the Prelude () with the () definition in my file rand.hs. Michael == [mich...@localhost ~]$ cat rand.hs import System.Random type Seed = Int randomNext :: Seed - Seed randomNext rand = if newRand 0 then newRand else newRand + 2147483647 where newRand = 16807 * lo - 2836 * hi (hi,lo) = rand `divMod` 127773 toDieRoll :: Seed - Int toDieRoll seed = (seed `mod` 6) + 1 rollDie :: Seed - (Int, Seed) rollDie seed = ((seed `mod` 6) + 1, randomNext seed) sumTwoDice :: Seed - (Int, Seed) sumTwoDice seed0 = let (die1, seed1) = rollDie seed0 (die2, seed2) = rollDie seed1 in (die1 + die2, seed2) () m n = \seed0 - let (result1, seed1) = m seed0 (result2, seed2) = n seed1 in (result2, seed2) [mich...@localhost ~]$ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org mailto: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] Getting the x out
If you want to just get the value out, meaning you'll get a program error if it happens to be Nothing, then you can use Data.Maybe.fromJust. But usually, you'd want to preserve the Nothing. Applicative or Monad is pretty good for this: import Control.Applicative (3+) $ safeDivision 10 5 the result will be Just 5.0 in this case, but if the division was incorrect it would be nothing. If you want to do something else, you can either pattern match on it: case safeDivision 10 5 of Just x - -- do something with x Nothing - -- do something else or use some functions from Data.Maybe. Say you want to evaluate to 1 instead of Nothing: import Data.Maybe fromMaybe 1 (safeDivision 10 5) -Ross On Apr 21, 2009, at 8:49 PM, michael rice wrote: How do I get the x out of Just x? Michael = safeDivision :: Float - Float - Maybe Float safeDivision x y = if y == 0 then Nothing else Just (x/y) *Main Data.List safeDivision 10 5 Just 2.0 *Main Data.List 3 + (safeDivision 10 5) interactive:1:0: No instance for (Num (Maybe Float)) arising from a use of `+' at interactive:1:0-22 Possible fix: add an instance declaration for (Num (Maybe Float)) In the expression: 3 + (safeDivision 10 5) In the definition of `it': it = 3 + (safeDivision 10 5) *Main Data.List ___ 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] Funny type signature question
There's nothing connecting the Enum/Bounded used in fromEnum and min/ maxBound to the toEnum, as there's an Int in the middle. Annotated very explicitly, the type inferrer probably sees something like: randomEnum :: (Enum a, Bounded a, RandomGen g) = Rand g a randomEnum = do let minb = (minBound :: a1) maxb = (maxBound :: a1) randVal - getRandomR (fromEnum minb, fromEnum maxb) -- a1 here return $ head [toEnum randVal, minb, maxb] -- putting minb and maxb in the list forces the unknown a1 to be a, because lists are homogeneous So you have to give it some clue what you really want. -Ross On Apr 2, 2009, at 2:18 PM, Peter Verswyvelen wrote: The type inferer seems to struggle to find the type of minBound and maxBound, and GHC asks to use a type annotation. To only way I see how to add a type annotation here is to use a GHC extension: {-# LANGUAGE ScopedTypeVariables #-} randomEnum :: forall a g. (Enum a, Bounded a, RandomGen g) = Rand g a randomEnum = do randVal - getRandomR (fromEnum (minBound::a), fromEnum (maxBound::a)) return $ toEnum randVal It is annoying when the type inferer encounters ambiguities - you also get this all the time when using OpenGL e.g. GL.colour - but I don't know how to solve this without adding type annotations On Thu, Apr 2, 2009 at 8:03 PM, Michael Snoyman mich...@snoyman.com wrote: I've butted into this problem multiple times, so I thought it's finally time to get a good solution. I don't even have the terminology to describe the issue, so I'll just post the code I'm annoyed with and hope someone understands what I mean. import Control.Monad.Random import System.Random data Marital = Single | Married | Divorced deriving (Enum, Bounded, Show) randomEnum :: (Enum a, Bounded a, RandomGen g) = Rand g a randomEnum = do let minb = minBound maxb = maxBound randVal - getRandomR (fromEnum minb, fromEnum maxb) return $ head [toEnum randVal, minb, maxb] -- if I do the obvious thing (return $ toEnum randVal) I get funny errors main = do stdGen - newStdGen let marital = evalRand randomEnum stdGen :: Marital putStrLn $ Random marital status: ++ show marital Any help is appreciated. Thanks! Michael ___ 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
Re: [Haskell-cafe] ANNOUNCE: vacuum-cairo: a cairo frontend to vacuum for live Haskell data visualization
Unfortunately the .DMG based frameworks do not have the cairo svg framework (or the opengl framework), and it's non-trivial to get it added on. If you need it, best bet right now is probably to go for a macports install. -Ross On Mar 31, 2009, at 8:01 AM, Sebastian Fischer wrote: On Mar 31, 2009, at 7:40 AM, Don Stewart wrote: I am pleased to announce the release of vacuum-cairo, a Haskell library for interactive rendering and display of values on the GHC heap using Matt Morrow's vacuum library. Awesome! I want to try this. I have problems though installing it on an Intel MacBook running $ ghc --version The Glorious Glasgow Haskell Compilation System, version 6.10.1 $ cabal --version cabal-install version 0.6.2 using version 1.6.0.2 of the Cabal library $ ghc-pkg list gtk /Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.1/./ package.conf: gtk-0.10.0 I have installed gtk2hs using the instructions at http://www.haskell.org/haskellwiki/Gtk2Hs#Using_the_GTK.2B_OS_X_Framework A simple cabal update; cabal install vacuum-cairo gives me: $ cabal install vacuum-cairo Resolving dependencies... cabal: cannot configure vacuum-cairo-0.3.1. It requires svgcairo -any There is no available version of svgcairo that satisfies -any I have installed libsvg-cairo using MacPorts and it seems installed in /opt/local/lib: $ ls /opt/local/lib/libsvg-cairo.* /opt/local/lib/libsvg-cairo.1.0.1.dylib /opt/local/lib/libsvg-cairo.1.dylib /opt/local/lib/libsvg-cairo.a /opt/local/lib/libsvg-cairo.dylib /opt/local/lib/libsvg-cairo.la But cabal-install still gives the same error. Even with --extra-lib- dirs set: $ cabal install --extra-lib-dirs=/opt/local/lib/ vacuum-cairo Resolving dependencies... cabal: cannot configure vacuum-cairo-0.3.1. It requires svgcairo -any There is no available version of svgcairo that satisfies -any Hence, I downloaded the tarball and tried to use this instead to install vacuum-cairo, which lead to another problem: I cannot install the vacuum package because of a dependencies conflict due to the package ghc-6.10.1 requiring two different versions of process: $ cabal install vacuum Resolving dependencies... cabal: 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 Funny. Any ideas on how to get this cool package installed? Thanks! Sebastian ___ 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] ANN: cmonad 0.1.1
I think my brain just exploded. On Mar 30, 2009, at 1:29 PM, Edward Kmett wrote: First, BASIC, now C. What's next, Haskell? =) -Edward Kmett On Sun, Mar 29, 2009 at 5:16 AM, Lennart Augustsson lenn...@augustsson.net wrote: I've uploaded my CMonad package to Hackage. It allows you to write Haskell code in a C style. Unfortunately, GHC lacks certain optimizations to make efficient code when using CMonad, so instead of C speed you get low speed. Example: Computing some Fibonacci numbers: fib = do { a - arrayU[40]; i - auto 0; a[0] =: 1; a[1] =: 1; for (i =: 2, (i :: EIO Int) 40, i += 1) $ do { a[i] =: a[i-1] + a[i-2]; }; retrn (a[39]); } Example: Copying stdin to stdout: cat = do { c - auto 0; while ((c =: getchar()) = 0) $ do { putchar(c); }; return (); } -- Lennart ___ 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
Re: [Haskell-cafe] Rational and % operator remix
I think you probably mean ==, the comparison operator (function), not = (assignment in let-forms or where-forms) -Ross On Mar 29, 2009, at 1:40 PM, michael rice wrote: Hi, Thanks again for the help last night. The second function cf2 is an attempt to reverse the process of the first function, i.e., given a rational number it returns a list of integers, possibly infinite, but you shouldn't get into trouble if you use 98%67 as input (output should be [1,2,6,5]). The interpreter is complaining about the '=' following the 'in' keyword. Is there a better way to state this? Michael import Data.Ratio cf :: [Int] - Rational cf (x:[]) = toRational x cf (x:xs) = toRational x + 1 / cf xs cf2 :: Rational - [Int] cf2 a = let ai = toRational (floor ((numerator a) / (denominator a))) in if a = ai then [a] else ai : cf2 ((toRational 1) / (subtract ai a)) ___ 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] Something wrong with happs.org?
I thought that HAppS has gone, replaced by happstack? http://happstack.com/ -Ross On Mar 24, 2009, at 11:32 AM, Vimal wrote: Hi, http://happs.org/ has some Javascript visible as plain text. It looks like some tags are missing in the page... I hope that's the right website, because it turned up first on my Google search happs with a nice description too. -- Vimal ___ 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] The votes are in!
Doesn't matter how many times you seq the results, the thunk has been forced. -Ross On Mar 24, 2009, at 4:45 PM, FFT wrote: I demand a recount! The one that launches the missile should have won! 2009/3/24 Eelco Lempsink ee...@lempsink.nl: The results of the Haskell logo competition are in! You can view them at http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/results.pl? num_winners=1id=E_d21b0256a4fd5ed7algorithm=beatpath Congratulations Jeff Wheeler! I'll set up a page with the results visibile. -- Regards, Eelco Lempsink ___ 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
Re: [Haskell-cafe] The votes are in!
import Diebold.Unsafe (unsafeChangeVotes) ... ? -Ross On Mar 24, 2009, at 4:47 PM, John Van Enk wrote: Unless there's a rogue unsafeChangeVotes call in there somewhere. On Tue, Mar 24, 2009 at 4:46 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: Doesn't matter how many times you seq the results, the thunk has been forced. -Ross On Mar 24, 2009, at 4:45 PM, FFT wrote: I demand a recount! The one that launches the missile should have won! 2009/3/24 Eelco Lempsink ee...@lempsink.nl: The results of the Haskell logo competition are in! You can view them at http://www.cs.cornell.edu/w8/~andru/cgi-perl/civs/results.pl? num_winners=1id=E_d21b0256a4fd5ed7algorithm=beatpath Congratulations Jeff Wheeler! I'll set up a page with the results visibile. -- Regards, Eelco Lempsink ___ 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 -- /jve ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] about Haskell code written to be too smart
As (yet another?) Haskell newbie, with a day job using Java (where keep it simple, stupid is not a principle, it's a language enforced requirement), I would much prefer the function is implemented in the most concise and idiomatic style that the writer is capable of. That is, either the zipWith...scanl solution (or its variants) or the state solution. I've found that I learn considerably more from functions written this way that also have a good documentation comment than from munching on the standard pattern matching recursion again and again. If the function is well described, and short in purpose and text, I can use the fact that with functional programming (with some exception) ensures that all I need to understand the behavior should be right in front of me and I can spend time learning the patterns. Just my 2 cents, -Ross On Mar 24, 2009, at 5:43 PM, Manlio Perillo wrote: Jonathan Cast ha scritto: [...] I think, in general, the best way to document the purpose of the function is -- | Split a function into a sequence of partitions of specified lenth takeList :: [Int] - [a] - [[a]] Note that I was not speaking about the best way to document a function. I was speaking about the best way to write a function, so that it may help someone who is learning Haskell. [...] Manlio ___ 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] Ease of Haskell development on OS X?
I tried making this work, but librsvg requires pango, and pango is a huge pain in the ass -- I managed to get the whole thing to compile, but now it can't find any fonts, apparently due to some dynaloading issues. I think if you need any of the extended modules (e.g. svgcairo, gl) that the DMG doesn't directly support then you're best served by shedding a couple tears and going with macports. The steps I used to get the broken version were (FYI -- doing this causes all fonts to load as the no-character square in all gtk2hs apps): export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig:/usr/local/lib/ pkgconfig:/Library/Frameworks/Cairo.framework/Resources/dev/lib/ pkgconfig:/Library/Frameworks/GLib.framework/Resources/dev/lib/ pkgconfig:/Library/Frameworks/Gtk.framework/Resources/dev/lib/pkgconfig export PATH=$PATH:/Library/Frameworks/GLib.framework/Resources/dev/bin cd pango-1.24.0 CFLAGS=-DFC_WEIGHT_EXTRABLACK=215 ./configure --prefix=/usr/local make -j4 sudo make install cd librsvg-2.26.0 ./configure --prefix=/usr/local make -j4 sudo make install cd gtk2hs-0.10.0 ./configure --disable-gio make -j4 sudo make install Running apps linked with this version of gtk2hs gets: (svgviewer:43314): Pango-CRITICAL **: No modules found: No builtin or dynamically loaded modules were found. PangoFc will not work correctly. This probably means there was an error in the creation of: '/usr/local/etc/pango/pango.modules' You should create this file by running: pango-querymodules '/usr/local/etc/pango/pango.modules' (svgviewer:43314): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderATSUI', script='latin' So if anyone knows what Pango is trying to do, maybe they could help resolve this. I'm probably going to ditch the use of GTK in my own project and use FFI bindings to Carbon/Win32, since I don't really need widgets for my own stuff and the whole family of GTK related packages is a total pain in the ass (as are most things in the GNU family of software, IMO) -Ross On Mar 21, 2009, at 10:13 AM, Colin Paul Adams wrote: Ross == Ross Mellgren rmm-hask...@z.odi.ac writes: Ross While there is not a .dmg for Gtk2Hs, you can use a .dmg Ross installed GHC with a .dmg installed Gtk, and then build Ross gtk2hs straight on top of that, without having to deal with Ross the dual-GHC macports mess.. Ross http://www.haskell.org/haskellwiki/Gtk2hs#Using_the_GTK.2B_OS_X_Framework I just tried this. The configure enables cairo, but does not enable svgcairo. Is there anyway round this, or do I have to revert to the macports gtk? (my application uses svgcairo) -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Ease of Haskell development on OS X?
Minor correction -- pango in general is installed with the .DMG of Gtk... it's pangoft2 (the freetype2 bindings) that librsvg requires and aren't provided. -Ross On Mar 21, 2009, at 12:35 PM, Ross Mellgren wrote: I tried making this work, but librsvg requires pango, and pango is a huge pain in the ass -- I managed to get the whole thing to compile, but now it can't find any fonts, apparently due to some dynaloading issues. I think if you need any of the extended modules (e.g. svgcairo, gl) that the DMG doesn't directly support then you're best served by shedding a couple tears and going with macports. The steps I used to get the broken version were (FYI -- doing this causes all fonts to load as the no-character square in all gtk2hs apps): export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig:/usr/local/lib/ pkgconfig:/Library/Frameworks/Cairo.framework/Resources/dev/lib/ pkgconfig:/Library/Frameworks/GLib.framework/Resources/dev/lib/ pkgconfig:/Library/Frameworks/Gtk.framework/Resources/dev/lib/ pkgconfig export PATH=$PATH:/Library/Frameworks/GLib.framework/Resources/dev/bin cd pango-1.24.0 CFLAGS=-DFC_WEIGHT_EXTRABLACK=215 ./configure --prefix=/usr/local make -j4 sudo make install cd librsvg-2.26.0 ./configure --prefix=/usr/local make -j4 sudo make install cd gtk2hs-0.10.0 ./configure --disable-gio make -j4 sudo make install Running apps linked with this version of gtk2hs gets: (svgviewer:43314): Pango-CRITICAL **: No modules found: No builtin or dynamically loaded modules were found. PangoFc will not work correctly. This probably means there was an error in the creation of: '/usr/local/etc/pango/pango.modules' You should create this file by running: pango-querymodules '/usr/local/etc/pango/pango.modules' (svgviewer:43314): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderATSUI', script='latin' So if anyone knows what Pango is trying to do, maybe they could help resolve this. I'm probably going to ditch the use of GTK in my own project and use FFI bindings to Carbon/Win32, since I don't really need widgets for my own stuff and the whole family of GTK related packages is a total pain in the ass (as are most things in the GNU family of software, IMO) -Ross On Mar 21, 2009, at 10:13 AM, Colin Paul Adams wrote: Ross == Ross Mellgren rmm-hask...@z.odi.ac writes: Ross While there is not a .dmg for Gtk2Hs, you can use a .dmg Ross installed GHC with a .dmg installed Gtk, and then build Ross gtk2hs straight on top of that, without having to deal with Ross the dual-GHC macports mess.. Ross http://www.haskell.org/haskellwiki/Gtk2hs#Using_the_GTK.2B_OS_X_Framework I just tried this. The configure enables cairo, but does not enable svgcairo. Is there anyway round this, or do I have to revert to the macports gtk? (my application uses svgcairo) -- Colin Adams Preston Lancashire ___ 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] Ease of Haskell development on OS X?
I didn't get any errors like that (nor do I remember ever having them), though if you want to paste them here maybe I can help with them. -Ross On Mar 21, 2009, at 1:27 PM, Colin Adams wrote: If I try this, pango fails to compile with lots of error messages about error: macro names must be identifiers. I think I've seen this before - some well-known Mac OSX problem? (I'm a linux man myself - so I'm not used to the mac) 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: I tried making this work, but librsvg requires pango, and pango is a huge pain in the ass -- I managed to get the whole thing to compile, but now it can't find any fonts, apparently due to some dynaloading issues. I think if you need any of the extended modules (e.g. svgcairo, gl) that the DMG doesn't directly support then you're best served by shedding a couple tears and going with macports. The steps I used to get the broken version were (FYI -- doing this causes all fonts to load as the no-character square in all gtk2hs apps): export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig:/usr/local/lib/pkgconfig:/ Library/Frameworks/Cairo.framework/Resources/dev/lib/pkgconfig:/ Library/Frameworks/GLib.framework/Resources/dev/lib/pkgconfig:/ Library/Frameworks/Gtk.framework/Resources/dev/lib/pkgconfig export PATH=$PATH:/Library/Frameworks/GLib.framework/Resources/dev/ bin cd pango-1.24.0 CFLAGS=-DFC_WEIGHT_EXTRABLACK=215 ./configure --prefix=/usr/local make -j4 sudo make install cd librsvg-2.26.0 ./configure --prefix=/usr/local make -j4 sudo make install cd gtk2hs-0.10.0 ./configure --disable-gio make -j4 sudo make install Running apps linked with this version of gtk2hs gets: (svgviewer:43314): Pango-CRITICAL **: No modules found: No builtin or dynamically loaded modules were found. PangoFc will not work correctly. This probably means there was an error in the creation of: '/usr/local/etc/pango/pango.modules' You should create this file by running: pango-querymodules '/usr/local/etc/pango/pango.modules' (svgviewer:43314): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderATSUI', script='latin' So if anyone knows what Pango is trying to do, maybe they could help resolve this. I'm probably going to ditch the use of GTK in my own project and use FFI bindings to Carbon/Win32, since I don't really need widgets for my own stuff and the whole family of GTK related packages is a total pain in the ass (as are most things in the GNU family of software, IMO) -Ross On Mar 21, 2009, at 10:13 AM, Colin Paul Adams wrote: Ross == Ross Mellgren rmm-hask...@z.odi.ac writes: Ross While there is not a .dmg for Gtk2Hs, you can use a .dmg Ross installed GHC with a .dmg installed Gtk, and then build Ross gtk2hs straight on top of that, without having to deal with Ross the dual-GHC macports mess.. Ross http://www.haskell.org/haskellwiki/Gtk2hs#Using_the_GTK.2B_OS_X_Framework I just tried this. The configure enables cairo, but does not enable svgcairo. Is there anyway round this, or do I have to revert to the macports gtk? (my application uses svgcairo) -- Colin Adams Preston Lancashire ___ 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] Ease of Haskell development on OS X?
(back to the list) Answers inline: On Mar 21, 2009, at 2:42 PM, Colin Adams wrote: Yes, that was the problem, and swapping the PATH order does the trick. Thanks. no prob. I must still have the macports stuff installed. Can you tell me how to get rid of it? if you really want to get rid of it I believe you just have to rm -rf / opt/local and remove any initialization hooks for /opt/local out of / etc/profile and ~/.bash_profile However I still can't install my program - I get missing dependencies for gtk glib cairo and svgcairo. I'm not really that savvy with the package registration magics -- on my system after doing sudo make install for gtk2hs, I get the packages properly registered. You can check the registered packages with ghc- pkg list. It could be that the package is registered local for your user, but the cabal install line you're using for the application includes --global (or your cabal configuration) so it won't look in the user config. I think Duncan answered some questions about this same problem recently, though I don't have a mailing list reference. I tried some of the gtk2hs demos - they work, but, for instance, the actionmenu demo does not put the menus up at the top of the screen, so it doesn't look like the framework integration has worked. Even with the integration everything is still GTK-ish. There's a separate framework that comes with the .dmg called ige-mac-integration that allows applications to meld with the mac environment better, but no gtk2hs bindings for this exist at the moment. Bindings would have to be created, and then you'd have to modify the application to make use of them (presumably with CPP or similar switch to control whether you want mac support, or just plain GTK) -Ross 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: I think there must be a version inconsistency with your GLib framework -- either not the most recent copy of the GTK+ DMG, or your path is flipped around and you're using a ports version. Run glib-mkenums --version to see what version you have... I have r...@hugo:~/tmpgtk/GLib.framework/Resources/dev/bin$ ./glib-mkenums --version glib-mkenums version glib-2.18.1 glib-mkenums comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of glib-mkenums under the terms of the GNU General Public License which can be found in the GLib source package. Sources, examples and contact information are available at http://www.gtk.org Particularly, the error you're getting is because your version of glib-mkenums doesn't expand @ENUMPREFIX@ -- if I run glib-mkenums with no arguments, my version reports @ENUMPREFIX@ as a valid subtitution: r...@hugo:~/tmpgtk/GLib.framework/Resources/dev/bin$ ./glib-mkenums Usage: glib-mkenums [options] [files...] --fhead text output file header --fprod text per input file production --ftail text output file trailer --eprod text per enum text (produced prior to value itarations) --vhead text value header, produced before iterating over enum values --vprod text value text, produced for each enum value --vtail text value tail, produced after iterating over enum values --comments text comment structure --template filetemplate file -h, --help show this help message -v, --version print version informations Production text substitutions: @EnumName@ PrefixTheXEnum @enum_name@prefix_the_xenum @ENUMNAME@ PREFIX_THE_XENUM @ENUMSHORT@THE_XENUM @ENUMPREFIX@ PREFIX @VALUENAME@PREFIX_THE_XVALUE @valuenick@the-xvalue @type@ either enum or flags @Type@ either Enum or Flags @TYPE@ either ENUM or FLAGS @filename@ name of current input file Does yours? You might try moving /Library/Frameworks/GLib.framework/Resources/ dev/bin to the front of your path before make'ing pango -- cd pango-1.24.0 export PATH=/Library/Frameworks/GLib.framework/Resources/dev/bin: $PATH make Hope this helps, -Ross On Mar 21, 2009, at 1:52 PM, Colin Adams wrote: Attached. 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: (taking this off list, to avoid noise) Could you attach pango-1.24.0/pango/pango-enum-types.h? Something hokey is going on -- this file is shipped with pango-1.24.0 but may be overwritten if your glib-mkenums does it differently. In any case, since it's (possibly) machine generated I would have to see what's going on at those lines to make progress. Also, if you could cd pango-1.24.0/pango, and run: gcc -E -DHAVE_CONFIG_H -I. -I.. -DG_LOG_DOMAIN=\Pango\ -DPANGO_ENABLE_BACKEND -DPANGO_ENABLE_ENGINE -DSYSCONFDIR=\/usr/local/etc\ -DLIBDIR=\/usr/local/lib\ -I.. -DG_DISABLE_CAST_CHECKS -I/Library/Frameworks/GLib.framework/Headers
Re: [Haskell-cafe] Ease of Haskell development on OS X?
Did the configure for gtk2hs claim that it was going to build svgcairo? If something is wrong with the librsvg install, it won't. -Ross On Mar 21, 2009, at 4:49 PM, Colin Adams wrote: OK - I added the --with-user-pkginfo flag. It nearly all works now - but still no svgcairo - ./configure doesn't find it. 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: (back to the list) Answers inline: On Mar 21, 2009, at 2:42 PM, Colin Adams wrote: Yes, that was the problem, and swapping the PATH order does the trick. Thanks. no prob. I must still have the macports stuff installed. Can you tell me how to get rid of it? if you really want to get rid of it I believe you just have to rm -rf /opt/local and remove any initialization hooks for /opt/local out of /etc/profile and ~/.bash_profile However I still can't install my program - I get missing dependencies for gtk glib cairo and svgcairo. I'm not really that savvy with the package registration magics -- on my system after doing sudo make install for gtk2hs, I get the packages properly registered. You can check the registered packages with ghc-pkg list. It could be that the package is registered local for your user, but the cabal install line you're using for the application includes --global (or your cabal configuration) so it won't look in the user config. I think Duncan answered some questions about this same problem recently, though I don't have a mailing list reference. I tried some of the gtk2hs demos - they work, but, for instance, the actionmenu demo does not put the menus up at the top of the screen, so it doesn't look like the framework integration has worked. Even with the integration everything is still GTK-ish. There's a separate framework that comes with the .dmg called ige-mac-integration that allows applications to meld with the mac environment better, but no gtk2hs bindings for this exist at the moment. Bindings would have to be created, and then you'd have to modify the application to make use of them (presumably with CPP or similar switch to control whether you want mac support, or just plain GTK) -Ross 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: I think there must be a version inconsistency with your GLib framework -- either not the most recent copy of the GTK+ DMG, or your path is flipped around and you're using a ports version. Run glib-mkenums --version to see what version you have... I have r...@hugo:~/tmpgtk/GLib.framework/Resources/dev/bin$ ./glib-mkenums --version glib-mkenums version glib-2.18.1 glib-mkenums comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of glib-mkenums under the terms of the GNU General Public License which can be found in the GLib source package. Sources, examples and contact information are available at http://www.gtk.org Particularly, the error you're getting is because your version of glib-mkenums doesn't expand @ENUMPREFIX@ -- if I run glib-mkenums with no arguments, my version reports @ENUMPREFIX@ as a valid subtitution: r...@hugo:~/tmpgtk/GLib.framework/Resources/dev/bin$ ./glib-mkenums Usage: glib-mkenums [options] [files...] --fhead text output file header --fprod text per input file production --ftail text output file trailer --eprod text per enum text (produced prior to value itarations) --vhead text value header, produced before iterating over enum values --vprod text value text, produced for each enum value --vtail text value tail, produced after iterating over enum values --comments text comment structure --template filetemplate file -h, --help show this help message -v, --version print version informations Production text substitutions: @EnumName@ PrefixTheXEnum @enum_name@prefix_the_xenum @ENUMNAME@ PREFIX_THE_XENUM @ENUMSHORT@THE_XENUM @ENUMPREFIX@ PREFIX @VALUENAME@PREFIX_THE_XVALUE @valuenick@the-xvalue @type@ either enum or flags @Type@ either Enum or Flags @TYPE@ either ENUM or FLAGS @filename@ name of current input file Does yours? You might try moving /Library/Frameworks/GLib.framework/Resources/ dev/bin to the front of your path before make'ing pango -- cd pango-1.24.0 export PATH=/Library/Frameworks/GLib.framework/Resources/dev/bin: $PATH make Hope this helps, -Ross On Mar 21, 2009, at 1:52 PM, Colin Adams wrote: Attached. 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: (taking this off list, to avoid noise) Could you attach pango-1.24.0/pango/pango-enum-types.h? Something hokey is going on -- this file is shipped with pango-1.24.0 but may be overwritten if your glib-mkenums does it differently. In any case, since it's (possibly) machine
Re: [Haskell-cafe] Ease of Haskell development on OS X?
Should be from pkg-config path, make sure your PKG_CONFIG_PATH is set to include /Library/Frameworks/{GLib,Gtk,Cairo}.framework Also, I had a problem where it couldn't find libpng -- I had to add / usr/X11/lib/pkgconfig to my pkg-config path. -Ross On Mar 21, 2009, at 5:02 PM, Colin Adams wrote: And the reason is that librsvg fails to find cairo, pangocairo and cairo-png. Where is it supposed to find them? 2009/3/21 Colin Adams colinpaulad...@googlemail.com: It didn't. 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: Did the configure for gtk2hs claim that it was going to build svgcairo? If something is wrong with the librsvg install, it won't. -Ross On Mar 21, 2009, at 4:49 PM, Colin Adams wrote: OK - I added the --with-user-pkginfo flag. It nearly all works now - but still no svgcairo - ./configure doesn't find it. 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: (back to the list) Answers inline: On Mar 21, 2009, at 2:42 PM, Colin Adams wrote: Yes, that was the problem, and swapping the PATH order does the trick. Thanks. no prob. I must still have the macports stuff installed. Can you tell me how to get rid of it? if you really want to get rid of it I believe you just have to rm -rf /opt/local and remove any initialization hooks for /opt/local out of /etc/profile and ~/.bash_profile However I still can't install my program - I get missing dependencies for gtk glib cairo and svgcairo. I'm not really that savvy with the package registration magics -- on my system after doing sudo make install for gtk2hs, I get the packages properly registered. You can check the registered packages with ghc-pkg list. It could be that the package is registered local for your user, but the cabal install line you're using for the application includes --global (or your cabal configuration) so it won't look in the user config. I think Duncan answered some questions about this same problem recently, though I don't have a mailing list reference. I tried some of the gtk2hs demos - they work, but, for instance, the actionmenu demo does not put the menus up at the top of the screen, so it doesn't look like the framework integration has worked. Even with the integration everything is still GTK-ish. There's a separate framework that comes with the .dmg called ige-mac-integration that allows applications to meld with the mac environment better, but no gtk2hs bindings for this exist at the moment. Bindings would have to be created, and then you'd have to modify the application to make use of them (presumably with CPP or similar switch to control whether you want mac support, or just plain GTK) -Ross 2009/3/21 Ross Mellgren rmm-hask...@z.odi.ac: I think there must be a version inconsistency with your GLib framework -- either not the most recent copy of the GTK+ DMG, or your path is flipped around and you're using a ports version. Run glib-mkenums --version to see what version you have... I have r...@hugo:~/tmpgtk/GLib.framework/Resources/dev/bin$ ./glib- mkenums --version glib-mkenums version glib-2.18.1 glib-mkenums comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of glib-mkenums under the terms of the GNU General Public License which can be found in the GLib source package. Sources, examples and contact information are available at http://www.gtk.org Particularly, the error you're getting is because your version of glib-mkenums doesn't expand @ENUMPREFIX@ -- if I run glib- mkenums with no arguments, my version reports @ENUMPREFIX@ as a valid subtitution: r...@hugo:~/tmpgtk/GLib.framework/Resources/dev/bin$ ./glib- mkenums Usage: glib-mkenums [options] [files...] --fhead text output file header --fprod text per input file production --ftail text output file trailer --eprod text per enum text (produced prior to value itarations) --vhead text value header, produced before iterating over enum values --vprod text value text, produced for each enum value --vtail text value tail, produced after iterating over enum values --comments text comment structure --template filetemplate file -h, --help show this help message -v, --version print version informations Production text substitutions: @EnumName@ PrefixTheXEnum @enum_name@prefix_the_xenum @ENUMNAME@ PREFIX_THE_XENUM @ENUMSHORT@THE_XENUM @ENUMPREFIX@ PREFIX @VALUENAME@PREFIX_THE_XVALUE @valuenick@the-xvalue @type@ either enum or flags @Type@ either Enum or Flags @TYPE@ either ENUM or FLAGS @filename@ name of current input file Does yours? You might try moving /Library/Frameworks/GLib.framework/Resources/dev/bin
Re: [Haskell-cafe] Ease of Haskell development on OS X?
While there is not a .dmg for Gtk2Hs, you can use a .dmg installed GHC with a .dmg installed Gtk, and then build gtk2hs straight on top of that, without having to deal with the dual-GHC macports mess.. http://www.haskell.org/haskellwiki/Gtk2hs#Using_the_GTK.2B_OS_X_Framework -Ross On Mar 20, 2009, at 2:10 PM, Jeff Heard wrote: cabal-install works for me. The one thing that would be REALLY REALLY nice (and I'm cc-ing Duncan on this) is a .dmg for Gtk2Hs on Mac OS X. There exists a ports build for it, but it won't use the GHC that is installed via .dmg to build it - it insists instead on installing ghc again via ports, which I find both odd and undesirable. It really comes down to the fact that gtk2hs is the only thing in the haskellverse that requires ports to get compiled in an intuitive way. On Fri, Mar 20, 2009 at 1:51 PM, Don Stewart d...@galois.com wrote: tom.davie: On 20 Mar 2009, at 18:46, Don Stewart wrote: tom.davie: On 20 Mar 2009, at 18:08, Don Stewart wrote: tom.davie: Other than chose the graphics card carefully, an iMac will do you very well. Hope that helps. This is very useful. Could the Mac users add information (and screenshots?) to the OSX wiki page, http://haskell.org/haskellwiki/OSX I'm not really sure there's much to add. It mostly just works™. Is there something that can be extracted from this discussion to add to it? Imagine you're new to Haskell, or the Mac. What do you need to know to get started developing new Haskell software? Is that information on the page? Thankfully, yes, all you need to know are either (a) go to haskell.org and download it, or (b) download macports, and port install ghc... Now you've got a Haskell environment like any other. I guess I could add a chunk of text about good editors, but I'm not sure if that's suitable, is it? Yes, anything that is relevant to the development experience on this platform. Remember: it is more than just getting ghc. How do they get hold of new libraries and apps? Is cabal-install available? ___ 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
Re: [Haskell-cafe] Ease of Haskell development on OS X?
Ah, true. Sorry, my mistake -- I forgot that wasn't supported with the framework version. -Ross On Mar 20, 2009, at 2:56 PM, Jeff Heard wrote: That one doesn't work with OpenGL, however and won't in the forseeable future.Incidentally, just now doing a ports install gtk2hs gives me the following error on my brand new MacBook: $ sudo port install gtk2hs ... stuff happens normally ... then: opt/local/bin/ghc +RTS -RTS -c tools/hierarchyGen/TypeGen.hs -o tools/hierarchyGen/TypeGen.o -O -itools/hierarchyGen -package-conf package.conf.inplace -hide-all-packages -package base package.conf.inplace: openBinaryFile: does not exist (No such file or directory) /opt/local/bin/ghc +RTS -RTS -c tools/callbackGen/HookGenerator.hs -o tools/callbackGen/HookGenerator.o -O -I. -itools/callbackGen -package-conf package.conf.inplace -hide-all-packages -package base package.conf.inplace: openBinaryFile: does not exist (No such file or directory) rm -rf glib/System/Glib.o glib/System/Glib_split/; mkdir -p glib/System/Glib_split /opt/local/bin/ghc +RTS -RTS -split-objs -c glib/System/Glib.hs -o glib/System/Glib.o -O -fffi -iglib -package-conf package.conf.inplace -hide-all-packages -ignore-package glib -package base -package-name glib-0.9.13 '-#includeglib-object.h' -I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include on the commandline: Warning: -fffi is deprecated: use -XForeignFunctionInterface or pragma {-# LANGUAGE ForeignFunctionInterface#-} instead package.conf.inplace: openBinaryFile: does not exist (No such file or directory) make[1]: *** [glib/System/Glib.o] Error 1 make: *** [all] Error 2 On Fri, Mar 20, 2009 at 2:27 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: While there is not a .dmg for Gtk2Hs, you can use a .dmg installed GHC with a .dmg installed Gtk, and then build gtk2hs straight on top of that, without having to deal with the dual-GHC macports mess.. http://www.haskell.org/haskellwiki/Gtk2hs#Using_the_GTK.2B_OS_X_Framework -Ross On Mar 20, 2009, at 2:10 PM, Jeff Heard wrote: cabal-install works for me. The one thing that would be REALLY REALLY nice (and I'm cc-ing Duncan on this) is a .dmg for Gtk2Hs on Mac OS X. There exists a ports build for it, but it won't use the GHC that is installed via .dmg to build it - it insists instead on installing ghc again via ports, which I find both odd and undesirable. It really comes down to the fact that gtk2hs is the only thing in the haskellverse that requires ports to get compiled in an intuitive way. On Fri, Mar 20, 2009 at 1:51 PM, Don Stewart d...@galois.com wrote: tom.davie: On 20 Mar 2009, at 18:46, Don Stewart wrote: tom.davie: On 20 Mar 2009, at 18:08, Don Stewart wrote: tom.davie: Other than chose the graphics card carefully, an iMac will do you very well. Hope that helps. This is very useful. Could the Mac users add information (and screenshots?) to the OSX wiki page, http://haskell.org/haskellwiki/OSX I'm not really sure there's much to add. It mostly just works™. Is there something that can be extracted from this discussion to add to it? Imagine you're new to Haskell, or the Mac. What do you need to know to get started developing new Haskell software? Is that information on the page? Thankfully, yes, all you need to know are either (a) go to haskell.org and download it, or (b) download macports, and port install ghc... Now you've got a Haskell environment like any other. I guess I could add a chunk of text about good editors, but I'm not sure if that's suitable, is it? Yes, anything that is relevant to the development experience on this platform. Remember: it is more than just getting ghc. How do they get hold of new libraries and apps? Is cabal-install available? ___ 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
Re: [Haskell-cafe] Status of Haskell under OsX
I use this configuration exclusively... it wasn't actually that hard to set up once I found out that the .pc files are shipped in a strange directory buried in the frameworks. I posted how I got it working back in December: http://sourceforge.net/mailarchive/message.php?msg_name=3E883695-30D3-4CBE-AD14-B08C24D343EF%40z.odi.ac -Ross On Mar 2, 2009, at 6:39 PM, Manuel M T Chakravarty wrote: BTW, there is a nice native version of GTK for Mac OS X as a proper framework: http://www.gtk-osx.org/ Unfortunately, it seems rather difficult to build gtk2hs with the GTK + framework as the framework doesn't support pkg-config and gtk2hs knows nothing about Mac frameworks. However, GHC has support for frameworks; so, it should be possible to get this to work. Manuel Arne Dehli Halvorsen: Manuel M T Chakravarty wrote: I'm planning to purchase a MacBookPro so I'm wondering how well Haskell is supported under this platform. At least two of the regular contributors to GHC work on Macs. That should ensure that Mac OS X is well supported. Installation is trivial with the Mac OS X installer package: http://haskell.org/ghc/download_ghc_6_10_1.html#macosxintel Hi, following on from this point: How does one get gtk2hs running on a mac? I have a MacBook Pro, and I've had ghc installed for some time now. (first in 6.8.2 (packaged), then 6.10.1 (packaged), then 6.8.2 via macports 1.6 then 6.10.1 via macports 1.7) I tried to install gtk2hs via macports, but it didn't work. (0.9.12? on 6.8.2, then on 6.10.1) Is there a recipe one could follow? Can I get the preconditions via macports, and then use cabal to install gtk2hs 0.10? Grateful for assistance, Arne D H Manuel ___ 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] ANN: gitit 0.5.1
Are you by chance using OSX? The file you attached was not a plain text file -- it was an RTF file. If you made this file on OSX and forgot to invoke the Format Make Plain Text command, it'll be an RTF file which I'm sure gitit will have no clue about. -Ross On Feb 26, 2009, at 10:21 AM, Hugo Pacheco wrote: Still nothing. No matter which config file I try (deleting almost every fields, newlines, etc), I always get the no parse error. On Thu, Feb 26, 2009 at 5:47 AM, Robin Green gree...@greenrd.org wrote: On Thu, 26 Feb 2009 14:30:17 + Hugo Pacheco hpach...@gmail.com wrote: Hi all, Under gitit 0.5.3 I always get Prelude.read: no parse when trying to load a configuration file. My previous file goes attached, but the sample config file from http://github.com/jgm/gitit/tree/master does not work also. I don't think you can actually do multiplication in the config file, as the sample config file tries to. Replace 2 * 1024 * 1024 with 200, and the sample config should work. -- Robin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- www.di.uminho.pt/~hpacheco ___ 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] Status of Haskell under OsX
I use Haskell under OSX only. I find it very well supported. -Ross On Feb 25, 2009, at 2:37 PM, Cristiano Paris wrote: Hi, I'm planning to purchase a MacBookPro so I'm wondering how well Haskell is supported under this platform. Thanks, Cristiano ___ 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: Re[6]: [Haskell-cafe] Re: speed: ghc vs gcc
Now perhaps I'll be stepping into some lines of fire as it seems like this thread is full of them. If I get in anyone's way please kindly hold your shot ;-) That said, video codecs are the kinds of things that usually benefit greatly from vectorization and parallelization right? These are two areas that have been getting concentration recently. I'm not really familiar with all the codecs involved, but it would probably be a great test case if someone could write a video codec (perhaps not H.264 since I recall someone saying it was ridiculously complicated) in C/C++ and in Haskell using all the DPH/parallelization tricks, as a comparison benchmark to improve the performance of the compiled code coming out of GHC. Having two pieces of code that are decently optimized and should do the same thing seems like it would make finding snags in the GHC performance and fixing them that much easier. Also, hunting with your bare hands rather than with a gun is provably more bad-ass ;-) -Ross On Feb 20, 2009, at 6:52 PM, Bulat Ziganshin wrote: Hello Peter, Saturday, February 21, 2009, 2:36:15 AM, you wrote: nothing should stop you from writing video games in Haskell since video codec isn't video game :))) but I've worked with people that wrote physics engines in C/C++, and they also had to hand optimize specifically for a certain compiler to get things fast. that's important signal. if you need to hand-optimize your code even if you use icl to compile it, using haskell will be like hunting with a hand instead of gun -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ 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] ANN : happs-tutorial 0.7
This is a known issue: http://hackage.haskell.org/trac/ghc/ticket/1993 Try: cabal install --ghc-options=-fregs-graph Crypto and then try installing happs-tutorial again. -Ross On Feb 11, 2009, at 4:31 PM, Daryoush Mehrtash wrote: When i try to cabal install happs-tutorial I get the following error: ghc: panic! (the 'impossible' happened) (GHC version 6.10.1 for i386-unknown-linux): RegAllocLinear.getStackSlotFor: out of stack slots, try -fregs- graph Please report this as a GHC bug: http://www.haskell.org/ghc/ reportabug cabal: Error: some packages failed to install: Crypto-4.1.0 failed during the building phase. The exception was: exit: ExitFailure 1 PBKDF2-0.3 depends on Crypto-4.1.0 which failed to install. happs-tutorial-0.7.1 depends on Crypto-4.1.0 which failed to install. happstack-helpers-0.11 depends on Crypto-4.1.0 which failed to install. Did I do anything wrong? Daryoush On Sat, Feb 7, 2009 at 4:36 PM, Creighton Hogg wch...@gmail.com wrote: Hello, I'm pleased to announce the release of happs-tutorial 0.7 on Hackage. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/happs-tutorial This is the first release of happs-tutorial built against the new Happstack project. Not much has changed in content since the last release except a few minor cleanups a little bit of reorganization. The 0.8 release will consist of more extensive additions, with the primary focus being a walk through of multimaster. I've taken over the development of the tutorial from Thomas Hartman, who has already put a rather massive effort into making HAppS/Happstack more accessible. Please feel free to e-mail me with any comments, errata, or threats of bodily harm. Cheers, Creighton Hogg ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Daryoush Weblog: http://perlustration.blogspot.com/ ___ 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] Additonal types for Foreign.C.Types
I think you can use Data.Word and Data.Int types for this, that is. Data.Word.Word16 == uint16_t, Data.Word.Word32 == uint32_t, etc. Data.Int.Int16 = int16_t, Data.Int.Int32 = int32_t, etc. There are Foreign.Storable.Storable instances for those. -Ross On Feb 10, 2009, at 6:32 AM, Maurí cio wrote: Hi, After reading an ISO draft for standard C, I found a few types that could be usefull when binding to libraries (these are from stdint.h): int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t What about if they were included in the next version of GHC Foreign.C.Types module? For instance, as: CInt8, CUInt8, CInt16 etc. Some libraries (e.g. sqlite) define function parameters that are supposed to always have a given size (e.g., sqlite defines sqlite3_int64). In order to have a portable binding to those libraries, it would be nice to have types in Haskell that also offer that guarantee. There are also a few other nice types, although I'm not sure they belong to standard modules. If they did, however, they could make life easier for those people writing higher level Haskell modules after standard C functions: complex, float complex, double complex (from complex.h) are used in functions like ccos, csin, cexp, csqrt etc. struct lconv (from locale.h) struct tm (from time.h) From wchar.h and wctype.h: mbstate_t, wint_t, wctrans_t, wctype_t. Do you think I could open a ticket for GHC proposing that? Best, Maurício ___ 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: Additonal types for Foreign.C.Types
The FFI spec says (at http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise3.html#x6-120003.2) : The argument types at[i] produced by fatype must be marshallable foreign types; that is, each ati is either (1) a basic foreign type or (2) a type synonym or renamed datatype of a marshallable foreign type. Moreover, the result type rt produced by frtype must be a marshallable foreign result type; that is, it is either a marshallable foreign type, the type (), or a type matching Prelude.IO t, where t is a marshallable foreign type or (). Earlier it defines the basic foreign types: The following types constitute the set of basic foreign types: * Char, Int, Double, Float, and Bool as exported by the Haskell 98 Prelude as well as * Int8, Int16, Int32, Int64, Word8, Word16, Word32, Word64, Ptr a, FunPtr a, and StablePtr a, for any type a, as exported by Foreign (Section 5.1). So, that list of types, or any type synonym. -Ross On Feb 10, 2009, at 3:56 PM, Maurí cio wrote: Yes, I can. Thanks. Just forget my idea, with this I can provide all those types in a library. I'm confused. When is it possible to use a type as a parameter to a foreign function call? My first guess was that I had to provide an instance for class Storable, but after I tried writing a complex-like type that way GHC told me my type was unaceptable. So I thought only types allowed by the compiler (including forall a. Ptr a) could be used that way. What is the rule? I've read all of FFI report and found nothing. Did I miss something? How can I make a type of mine acceptable? Why are Data.Int acceptable, and how could I know that? Thanks, Maurício I think you can use Data.Word and Data.Int types for this, that is. (...) After reading an ISO draft for standard C, I found a few types that could be usefull when binding to libraries (these are from stdint.h): int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t (...) ___ 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: Additonal types for Foreign.C.Types
fatype is the function argument type. atype[i] are type arguments. qtycon is a qualified (e.g. possibly with module prefix) type constructor, e.g. Just So, for example if you have: foreign import ccall string.h strlen cstrlen :: Ptr CChar - IO CSize fatype - ftype :: ftype fatype :: fatype qtycon Ptr atype1 CChar fatype :: frtype qtycon IO atype1 CSize (I struggled a bit with finding a good way to communicate the productions chosen, so bear with me) Make sense? -Ross On Feb 10, 2009, at 6:13 PM, Maurí cio wrote: The FFI spec says (at http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise3.html#x6-120003.2) : There I see: --- Foreign types are produced according to the following grammar: ftype -- frtype | fatype - ftype frtype -- fatype | () fatype -- qtycon atype[1] ... atype[k] (k 0) --- I can't understand the qtycon atype[1]... line. I did search haskell 98 report syntax reference, and saw how qtycon and tycon are defined, but I could not understand how they are used here. Thanks for your help, Maurício ___ 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] about integer and float operations
Prelude let i2fDiv a b = fromIntegral a / fromIntegral b Prelude :t i2fDiv i2fDiv :: (Integral a, Fractional b, Integral a1) = a - a1 - b Prelude 10 `i2fDiv` 3 3.3335 That what you're looking for? -Ross On Feb 4, 2009, at 4:22 PM, Manlio Perillo wrote: Manlio Perillo ha scritto: [...] I personally prefer the Python solution, where we have two operators with the same behaviour over all the numbers. In Haskell, something like (/) :: (Num a, Real b) = a - a - b This should be (/) :: (Num a, Fractional b) = a - a - b but I'm not sure it is correct. (//) :: (Num a, Integral b) = a - a - b Manlio Perillo ___ 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] why typeRepArgs (typeOf hello) is [Char] ?
The type of hello is String, which is [Char], which is really [] Char (that is, the list type of kind * - *, applied to Char). 1, 'a', and True are all simple types (I'm sure there's a more particular term, maybe monomorphic?) with no type arguments. [] has a type argument, Char. Consider: Prelude Data.Typeable typeRepArgs (typeOf (Just 1)) [Integer] and Prelude Data.Typeable typeRepArgs (typeOf (Left 'a' :: Either Char Int)) [Char,Int] -- typeRepArgs is giving you the arguments of the root type application, [] (list) in your case, Maybe and Either for the two examples I gave. Does this make sense? -Ross On Feb 2, 2009, at 3:09 PM, minh thu wrote: Hello, With Data.Typeable : *Graph typeRepArgs (typeOf 1) [] *Graph typeRepArgs (typeOf 'a') [] *Graph typeRepArgs (typeOf True) [] *Graph typeRepArgs (typeOf hello) [Char] I don't understand why the latter is not []. Could someone explain it ? Thank you, Thu ___ 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] why typeRepArgs (typeOf hello) is [Char] ?
Sure: (+) :: Integer - Integer - Integer (really Num a = a - a - a, but we'll use the defaulted one) Which is really (+) :: - Integer (- Integer Integer)(that is, the function type constructor is * - * - * and right associative) So when you say typeRepArgs (typeOf (+)) you get Integer and (- Integer Integer), which pretty-prints as (Integer - Integer) It is possible, but you have to check if the type constructor is really a function type, e.g.: import Data.Typeable funTyCon :: TyCon funTyCon = mkTyCon - argsOf :: TypeRep - [TypeRep] argsOf ty | typeRepTyCon ty == funTyCon = let (x:y:[]) = typeRepArgs ty in x : argsOf y | otherwise = [] *Main Data.Typeable let f = (undefined :: Int - Char - String - ()) *Main Data.Typeable argsOf (typeOf f) [Int,Char,[Char]] -Ross On Feb 2, 2009, at 3:27 PM, minh thu wrote: Thanks. Could you add to your explanation this one : *Graph typeRepArgs (typeOf (+)) [Integer,Integer - Integer] In fact, I tried to write a function that would give the types used by a function, for instance [Integer, Integer, Integer] for (+) (the last one would be the 'return' type). So I applied recursively typeRepArgs to the second element of the list (if any) (here, Integer - Integer). It worked well until I tried it on a function like :: Char - Int - [Char] where the last recursive call gives [Char] instead of []. Is it possible to write such a function ? Thank you, Thu 2009/2/2 Ross Mellgren rmm-hask...@z.odi.ac: The type of hello is String, which is [Char], which is really [] Char (that is, the list type of kind * - *, applied to Char). 1, 'a', and True are all simple types (I'm sure there's a more particular term, maybe monomorphic?) with no type arguments. [] has a type argument, Char. Consider: Prelude Data.Typeable typeRepArgs (typeOf (Just 1)) [Integer] and Prelude Data.Typeable typeRepArgs (typeOf (Left 'a' :: Either Char Int)) [Char,Int] -- typeRepArgs is giving you the arguments of the root type application, [] (list) in your case, Maybe and Either for the two examples I gave. Does this make sense? -Ross On Feb 2, 2009, at 3:09 PM, minh thu wrote: Hello, With Data.Typeable : *Graph typeRepArgs (typeOf 1) [] *Graph typeRepArgs (typeOf 'a') [] *Graph typeRepArgs (typeOf True) [] *Graph typeRepArgs (typeOf hello) [Char] I don't understand why the latter is not []. Could someone explain it ? Thank you, Thu ___ 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] C-like Haskell
Duncan, I think you must have some magics -- on my machine the original code also takes forever. Running with +RTS -S indicates it's allocating several gig of memory or more. Applying some bang patterns gives me ~8s for 10^8 and somewhat more than a minute for 10^9: {-# LANGUAGE BangPatterns #-} module Main where import Data.Int main = putStrLn $ show $ circ2 (10^8) circ2 :: Int64 - Int64 circ2 r = ((1+4*r) + 4 * (go (rs+1) r 1 0)) where rs = r^2 go :: Int64 - Int64 - Int64 - Int64 - Int64 go !rad !x !y !sum | x y = sum | rad = rs = go (rad+1+2*y) x (y+1) (sum+1+2*(x-y)) | otherwise = go (rad+1-2*x) (x-1) y sum 10^8: r...@hugo:~$ time ./circ-bangpatterns +RTS -t ./circ-bangpatterns +RTS -t 31415926535867961 ghc: 9120 bytes, 1 GCs, 2432/2432 avg/max bytes residency (1 samples), 1M in use, 0.00 INIT (0.00 elapsed), 8.15 MUT (8.31 elapsed), 0.00 GC (0.00 elapsed) :ghc real0m8.315s user0m8.154s sys 0m0.050s 10^9: r...@hugo:~$ time ./circ-bangpatterns +RTS -t ./circ-bangpatterns +RTS -t 3141592653589764829 ghc: 9336 bytes, 1 GCs, 2432/2432 avg/max bytes residency (1 samples), 1M in use, 0.00 INIT (0.00 elapsed), 80.49 MUT (82.68 elapsed), 0.00 GC (0.00 elapsed) :ghc real1m22.684s user1m20.490s sys 0m0.473s The C program is quite fast: r...@hugo:~$ time ./circ-orig 1302219321 real0m1.073s user0m1.039s sys 0m0.006s -Ross On Jan 28, 2009, at 8:06 PM, Duncan Coutts wrote: On Wed, 2009-01-28 at 16:42 -0800, drblanco wrote: I do already have the number I wanted, but was wondering how this could be made faster, or even why it's so slow. This is all on GHC 6.8.3 under OS X Intel, using ghc -O2. I'm not exactly sure what's different, but for me it works pretty well. I put back in the Int64 type signature. For comparison, the C code below runs in 1 second. You've got a faster machine than me :-) I compiled both the Haskell and C versions to standalone executables with ghc/gcc -O2 and ran them with time. C version: $ time ./circ 3141592649589764829 real0m2.430s user0m2.428s sys 0m0.000s Haskell version: time ./circ2 3141592653589764829 real0m2.753s user0m2.756s sys 0m0.000s Not too bad I'd say! :-) I was using ghc-6.10 for this test. It would appear that ghc-6.8 is a bit slower, I get: 3141592653589764829 real0m5.767s user0m5.768s sys 0m0.000s Now the other difference is that I'm using a 64bit machine so perhaps ghc just produces terrible code for Int64 on 32bit machines. Duncan ___ 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: C-like Haskell
Yeah, you know after sending the email (never a better time) I noticed that the C version wasn't spitting out the right answer. I'm not really sure why, I just replaced bigint with int64_t from stdint.h. -Ross On Jan 28, 2009, at 8:32 PM, Benedikt Huber wrote: Ross Mellgren schrieb: Duncan, I think you must have some magics -- on my machine the original code also takes forever. Running with +RTS -S indicates it's allocating several gig of memory or more. Applying some bang patterns gives me ~8s for 10^8 and somewhat more than a minute for 10^9: Hi, same here, with bang patterns ~100s / 1Mb but The C program is quite fast: r...@hugo:~$ time ./circ-orig 1302219321 looks wrong to me real0m1.073s cafe(0) $ time ./gauss 3141592649589764829 real0m17.894s So my 32-bit machine is really slow ... benedikt On Wed, 2009-01-28 at 16:42 -0800, drblanco wrote: I do already have the number I wanted, but was wondering how this could be made faster, or even why it's so slow. This is all on GHC 6.8.3 under OS X Intel, using ghc -O2. I'm not exactly sure what's different, but for me it works pretty well. I put back in the Int64 type signature. For comparison, the C code below runs in 1 second. You've got a faster machine than me :-) I compiled both the Haskell and C versions to standalone executables with ghc/gcc -O2 and ran them with time. C version: $ time ./circ 3141592649589764829 real0m2.430s user0m2.428s sys0m0.000s Haskell version: time ./circ2 3141592653589764829 real0m2.753s user0m2.756s sys0m0.000s Not too bad I'd say! :-) I was using ghc-6.10 for this test. It would appear that ghc-6.8 is a bit slower, I get: 3141592653589764829 real0m5.767s user0m5.768s sys0m0.000s Now the other difference is that I'm using a 64bit machine so perhaps ghc just produces terrible code for Int64 on 32bit machines. Duncan ___ 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] C-like Haskell
Apparently 64-bit GHC is sufficiently advanced to be indistinguishable from magic. Now, if only there was a 64-bit binary for Mac OS X :-/ -Ross On Jan 28, 2009, at 9:06 PM, Jake McArthur wrote: Ross Mellgren wrote: Duncan, I think you must have some magics -- on my machine the original code also takes forever. Running with +RTS -S indicates it's allocating several gig of memory or more. Applying some bang patterns gives me ~8s for 10^8 and somewhat more than a minute for 10^9 It works great for me. 64 bit, GHC 6.10.1, no bang patterns or other magic. Works about the same with both Int and Int64. % time ./ctest 3141592649589764829 real0m2.614s user0m2.610s sys 0m0.003s % time ./hstest 3141592653589764829 real0m3.878s user0m3.870s sys 0m0.003s % ./hstest +RTS -S ./hstest +RTS -S AllocCopied LiveGCGC TOT TOT Page Flts bytes bytes bytes user elapuserelap 3141592653589764829 8512 688 17136 0.00 0.003.943.9400 (Gen: 1) 0 0.00 0.00 8,512 bytes allocated in the heap 688 bytes copied during GC 17,136 bytes maximum residency (1 sample(s)) 19,728 bytes maximum slop 1 MB total memory in use (0 MB lost due to fragmentation) Generation 0: 0 collections, 0 parallel, 0.00s, 0.00s elapsed Generation 1: 1 collections, 0 parallel, 0.00s, 0.00s elapsed INIT time0.00s ( 0.00s elapsed) MUT time3.94s ( 3.94s elapsed) GCtime0.00s ( 0.00s elapsed) EXIT time0.00s ( 0.00s elapsed) Total time3.94s ( 3.94s elapsed) %GC time 0.0% (0.0% elapsed) Alloc rate2,158 bytes per MUT second Productivity 99.9% of total user, 100.0% of total elapsed ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Template Haskell very wordy w/r/t Decs and Types
Hi all, I'm writing a small module that exposes a template haskell splice that takes a (very simplified) C struct definition and builds: - A data type definition, - an instance for Data.Binary.Binary, - and optionally a pretty print function for it However, it seems to do this I have to write a bunch of really ugly code that builds up the TH data structures by hand because quoting only works with splices for expressions, or so it seems. For example, to generate the binary instance I have this code: import qualified Language.Haskell.TH as TH -- tyname is the name of the data type I've already created, as a TH.Name -- tempnames is a list of temporary variable names that are used in lambda patterns -- fields is a list of tuples describing each field -- makeGetExp recursively builds a monadic computation consisting mostly of Binary.getWord32be = \ tempvar - ... binaryInstDec - liftM (TH.InstanceD [] (TH.AppT (TH.ConT $ TH.mkName Data.Binary.Binary) (TH.ConT tyname))) [d| get = $(makeGetExp (reverse $ zip fields tempnames) returnExp) put = undefined |] I'd really rather write: binaryInstDec - [d| instance Binary.Binary $(tyname) where get = $(makeGetExp (reverse $ zip fields tempnames) returnExp) put = undefined |] But GHC gives me a syntax error on the tyname splice. The docs seem to indicate this is the way it is -- that splices in type locations is plain not implemented. My question is whether or not this is just the way it is, and people writing TH declaration splices tend to have to start manually assembling a bunch of it, or is there some trick I've missed? Perhaps even better are there some tricks that people tend to use to make this less painful? I did try using some of the lowercased monadic constructors in Language.Haskell.TH.Lib but I didn't seem to get anything more succint out of it. -Ross P.S. This is for a one-off weekend project, and the code is fugly, so I'm not posting it in its entirety here. If you want the whole module and are willing not to laugh, I'd be glad to send it along ;-) Background: I'm doing this because I'm writing a tool to snoop around the filesystem structures of HFS+ to try and help a friend recover some data off a sufficiently dead drive that fsck doesn't want to touch it, and I don't want to pay money just to find out the drive is too toasty to pull out the data. In any case, the HFS+ docs have a bunch of C struct definitions that comprise the structures, and I got tired of hand-writing data definitions and binary instances, so I figured I'd make TH do it for me. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generalizing a filter-making function
makeFilter :: (b - b - Bool) - (a - b) - b - a - Bool makeFilter (==) proj expected = (expected ==) . proj makeEqFilter :: Eq b = (a - b) - b - a - Bool makeEqFilter = makeFilter (==) Then you have a foo: data Foo = Foo { fooA :: String, fooB :: Int } foos = [Foo a 1, Foo b 2] filter (makeEqFilter fooA 1) foos and so on. Though this is not really buying you all that much over filter ((1 ==) . fooA) foos Or for storing data Query a = Query String (a - Bool) let myQuery = Query Test if fst is 1 ((1 ==) . fst) ... filter myQuery foos Does this help? -Ross On Jan 23, 2009, at 4:20 PM, Dominic Espinosa wrote: Novice question here. Sorry if the post is wordy. In the following code (which doesn't actually compile as-is), I'm trying to generalize these 'make*Filter' functions into a single 'makeFilter' function. However, I can't get the types to work right. Foo is a tuple type on which a large number of accessor functions are defined. All of them have type Foo - Int, Foo - String, or Foo - [a] (so far). I tried defining 'Query' using exsistential types instead, but had difficulty with 'escaped type variables' when I tried to write a generalized 'makeFilter' function. The general point of makeFilter is to take as parameters a Query, a value, a comparison function, and then return a function (Foo - Bool). This returned function takes as its argument an object of type Foo, applies the function 'q' to it, compares that value to 'val', and finally returns a Bool. Later on in the program, a list of these filter functions is to be used with a list of Foo objects, to determine which Foo objects satisfy all of the filters. Advice would be greatly appreciated. --- code --- data Query a = Query { query_identifier :: String, query_func :: (Foo - a) } makeIntFilter :: Query Int - Int - (Int - Int - Bool) - (Foo - Bool) makeIntFilter q val cmp = (\k - val `cmp` (query_func q $ k)) makeStringFilter :: Query String - String - (String - String - Bool) - (Foo - Bool) makeStringFilter q val cmp = (\k - val `cmp` (query_func q $ k)) -- ??? broken, and the 'cmp' argument is thrown away, which seems wrong makeMemberFilter :: Eq a = Query [a] - a - (a - a - a) - (Foo - Bool) makeMemberFilter q val cmp =(\k - val `elem` (query_func q $ 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] Generalizing a filter-making function
Parsec is an awesome piece of software. Throw away anything you might know from writing parsers in something else -- writing parsers with parsec is so succinct you can use it most anytime without feeling like you're resorting to it. -Ross On Jan 23, 2009, at 11:26 PM, Dominic Espinosa wrote: Thanks, that does help. I see I was unnecessarily passing a function parameter (as a newcomer to Haskell, I tend to forget how to properly use composition). The reason to do these maneuvers is that the particular accessor function to use is being parsed from user input. The main problem is along the lines of: given a user input string such as s 5, t 'baz', return a list of all Foos f such that (s f 5) and ('baz' `elem` $ t f). Someone else tipped me off about Parsec's expression parsing support, so I need to look at that as well. The expressions to be parsed are very minimal, however, so I'm not sure it's entirely necessary. Thanks again. On Fri, Jan 23, 2009 at 05:39:07PM -0500, Ross Mellgren wrote: makeFilter :: (b - b - Bool) - (a - b) - b - a - Bool makeFilter (==) proj expected = (expected ==) . proj makeEqFilter :: Eq b = (a - b) - b - a - Bool makeEqFilter = makeFilter (==) Then you have a foo: data Foo = Foo { fooA :: String, fooB :: Int } foos = [Foo a 1, Foo b 2] filter (makeEqFilter fooA 1) foos and so on. Though this is not really buying you all that much over filter ((1 ==) . fooA) foos Or for storing data Query a = Query String (a - Bool) let myQuery = Query Test if fst is 1 ((1 ==) . fst) ... filter myQuery foos Does this help? -Ross On Jan 23, 2009, at 4:20 PM, Dominic Espinosa wrote: Novice question here. Sorry if the post is wordy. In the following code (which doesn't actually compile as-is), I'm trying to generalize these 'make*Filter' functions into a single 'makeFilter' function. However, I can't get the types to work right. Foo is a tuple type on which a large number of accessor functions are defined. All of them have type Foo - Int, Foo - String, or Foo - [a] (so far). I tried defining 'Query' using exsistential types instead, but had difficulty with 'escaped type variables' when I tried to write a generalized 'makeFilter' function. The general point of makeFilter is to take as parameters a Query, a value, a comparison function, and then return a function (Foo - Bool). This returned function takes as its argument an object of type Foo, applies the function 'q' to it, compares that value to 'val', and finally returns a Bool. Later on in the program, a list of these filter functions is to be used with a list of Foo objects, to determine which Foo objects satisfy all of the filters. Advice would be greatly appreciated. --- code --- data Query a = Query { query_identifier :: String, query_func :: (Foo - a) } makeIntFilter :: Query Int - Int - (Int - Int - Bool) - (Foo - Bool) makeIntFilter q val cmp = (\k - val `cmp` (query_func q $ k)) makeStringFilter :: Query String - String - (String - String - Bool) - (Foo - Bool) makeStringFilter q val cmp = (\k - val `cmp` (query_func q $ k)) -- ??? broken, and the 'cmp' argument is thrown away, which seems wrong makeMemberFilter :: Eq a = Query [a] - a - (a - a - a) - (Foo - Bool) makeMemberFilter q val cmp =(\k - val `elem` (query_func q $ 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] OS X build failure of Gtk2Hs from MacPorts
I personally spurned MacPorts for this reason (and others). I've had good success using the GTK+ Aqua framework from http://www.gtk- osx.org/ and manually compiling pkg-config and gtk2hs from the darcs repository. The only trick was to set PKG_CONFIG_PATH appropriately before running gtk2hs' configure script: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/Library/Frameworks/ Cairo.framework/Resources/dev/lib/pkgconfig:/Library/Frameworks/ GLib.framework/Resources/dev/lib/pkgconfig:/Library/Frameworks/ Gtk.framework/Resources/dev/lib/pkgconfig Also had to --disable-gio to gtk2hs' configure. -Ross On Jan 17, 2009, at 5:58 PM, Jeff Heard wrote: That would probably be the problem, then, yes. I'm still using GHC 6.8.3 in most of my code, but MacPorts doesn't respect the existing installation of GHC 6.8.3 that I installed via the DMG package on http://haskell.org/ghc On Sat, Jan 17, 2009 at 5:56 PM, Yitzchak Gale g...@sefer.org wrote: Jeff, I'm not sure if this is causing the problem you're referring to, but MacPorts is at GHC 6.10 while Gtk2Hs doesn't support that yet. Regards, Yitz ___ 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] Comments from OCaml Hacker Brian Hurt
For what it's worth, many (most/all?) programmers I know in person don't have the slightest clue about Category Theory and they may have known about abstract algebra once upon a time but certainly don't remember any of it now. They usually understand the concepts perfectly well enough but by lay terms or by no particular name at all. Personally, I don't mind it too much if the generic typeclasses are named using extremely accurate terms like Monoid, but saying that someone should then look up the abstract math concept and try to map this to something very concrete and simple such as a string seems like wasted effort. Usually when encountering something like Monoid (if I didn't already know it), I'd look it up in the library docs. The problem I've had with this tactic is twofold: First, the docs for the typeclass usually don't give any practical examples, so sometimes it's hard to be sure that the append in mappend means what you think it means. Second is that there appears to be no way to document an _instance_. It would be really handy if there were even a single line under Instances Monoid ([] a) that explained how the type class was implemented for the list type. As it is, if you know what a Monoid is already, it's easy to figure out how it would be implemented. If you don't, you're either stuck reading a bunch of pages on the generic math term monoid and then finally realizing that it means appendable (and other similar things), or grovelling through the library source code seeing how the instance is implemented. My 2 cents, -Ross On Jan 15, 2009, at 11:36 AM, Lennart Augustsson wrote: Most people don't understand pure functional programming either. Does that mean we should introduce unrestricted side effects in Haskell? -- Lennart On Thu, Jan 15, 2009 at 4:22 PM, Thomas DuBuisson thomas.dubuis...@gmail.com wrote: On Thu, Jan 15, 2009 at 4:12 PM, Sittampalam, Ganesh ganesh.sittampa...@credit-suisse.com wrote: Lennart Augustsson wrote: I have replied on his blog, but I'll repeat the gist of it here. Why is there a fear of using existing terminology that is exact? Why do people want to invent new words when there are already existing ones with the exact meaning that you want? If I see Monoid I know what it is, if I didn't know I could just look on Wikipedia. If I see Appendable I can guess what it might be, but exactly what does it mean? I would suggest that having to look things up slows people down and might distract them from learning other, perhaps more useful, things about the language. Exactly. For example, the entry for monoid on Wikipedia starts: In abstract algebra, a branch of mathematics, a monoid is an algebraic structure with a single, associative binary operation and an identity element. I've had some set theory, but most programmers I know have not. ___ 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] Comments from OCaml Hacker Brian Hurt
Of course not, the wikipedians would probably have your head for notability guidelines or something ;-) But seriously, I would have saved many hours of my life and probably many future ones if type class instances were documented and showed up in the haddock docs. -Ross On Jan 15, 2009, at 11:53 AM, Lennart Augustsson wrote: By no means do I suggest that Wikipedia should replace Haskell library documentation. I think the libraries should be documented in a mostly stand-alone way (i.e., no references to old papers etc.). In the case of Monoid, a few lines of text is enough to convey the meaning of it and gives an example. -- Lennart On Thu, Jan 15, 2009 at 4:46 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: For what it's worth, many (most/all?) programmers I know in person don't have the slightest clue about Category Theory and they may have known about abstract algebra once upon a time but certainly don't remember any of it now. They usually understand the concepts perfectly well enough but by lay terms or by no particular name at all. Personally, I don't mind it too much if the generic typeclasses are named using extremely accurate terms like Monoid, but saying that someone should then look up the abstract math concept and try to map this to something very concrete and simple such as a string seems like wasted effort. Usually when encountering something like Monoid (if I didn't already know it), I'd look it up in the library docs. The problem I've had with this tactic is twofold: First, the docs for the typeclass usually don't give any practical examples, so sometimes it's hard to be sure that the append in mappend means what you think it means. Second is that there appears to be no way to document an _instance_. It would be really handy if there were even a single line under Instances Monoid ([] a) that explained how the type class was implemented for the list type. As it is, if you know what a Monoid is already, it's easy to figure out how it would be implemented. If you don't, you're either stuck reading a bunch of pages on the generic math term monoid and then finally realizing that it means appendable (and other similar things), or grovelling through the library source code seeing how the instance is implemented. My 2 cents, -Ross On Jan 15, 2009, at 11:36 AM, Lennart Augustsson wrote: Most people don't understand pure functional programming either. Does that mean we should introduce unrestricted side effects in Haskell? -- Lennart On Thu, Jan 15, 2009 at 4:22 PM, Thomas DuBuisson thomas.dubuis...@gmail.com wrote: On Thu, Jan 15, 2009 at 4:12 PM, Sittampalam, Ganesh ganesh.sittampa...@credit-suisse.com wrote: Lennart Augustsson wrote: I have replied on his blog, but I'll repeat the gist of it here. Why is there a fear of using existing terminology that is exact? Why do people want to invent new words when there are already existing ones with the exact meaning that you want? If I see Monoid I know what it is, if I didn't know I could just look on Wikipedia. If I see Appendable I can guess what it might be, but exactly what does it mean? I would suggest that having to look things up slows people down and might distract them from learning other, perhaps more useful, things about the language. Exactly. For example, the entry for monoid on Wikipedia starts: In abstract algebra, a branch of mathematics, a monoid is an algebraic structure with a single, associative binary operation and an identity element. I've had some set theory, but most programmers I know have not. ___ 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
Re: [Haskell-cafe] Comments from OCaml Hacker Brian Hurt
On Jan 15, 2009, at 1:21 PM, David Menendez wrote: On Thu, Jan 15, 2009 at 11:46 AM, Ross Mellgren rmm- hask...@z.odi.ac wrote: Second is that there appears to be no way to document an _instance_. It would be really handy if there were even a single line under Instances Monoid ([] a) that explained how the type class was implemented for the list type. As it is, if you know what a Monoid is already, it's easy to figure out how it would be implemented. Not necessarily. Any instance of MonadPlus (or Alternative) has at least two reasonable Monoid instances: (mplus, mzero) and (liftM2 mappend, return mempty). [] uses the first and Maybe uses the second. Sorry my brain apparently misfired writing the original email. What I meant to say is that for the Monoid instance on [a] it's fairly easy (knowing what a Monoid is) to figure out how it's implemented, but that's not true for other classes or instances. That is to say, I agree with you, and intended to up front ;-) -Ross ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] nested function application question
Did you mean: B.intercalate (B.intercalate ByteString [ByteString]) [ByteString] ($) applies all the way to the right, so you were giving the inner intercalate two lists of ByteString. -Ross On Jan 5, 2009, at 1:17 PM, Galchin, Vasili wrote: Hi Max, That is what should happen The inner B.intercalate will produce the ByteString to be used by the B.intercalate. ?? Vasili On Mon, Jan 5, 2009 at 12:13 PM, Max Rabkin max.rab...@gmail.com wrote: 2009/1/5 Galchin, Vasili vigalc...@gmail.com: Hello, I have the following: B.intercalate $ B.intercalate ByteString [ByteString] [ByteString] I get a type error with this. If I comment out the 2nd B.intercalate and the third parameter I get no type errors. B.intercalate needs a ByteString and a list of ByteStrings. Two B.intercalates need two ByteStrings and two lists of ByteStrings. --Max ___ 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] nested function application question
In this case you have to use parens -- two dollar signs, like this B.intercalate $ B.intercalate ByteString [ByteString] $ [ByteString] would also not type check -- it is exactly equivalent to your first example: B.intercalate (B.intercalate ByteString [ByteString] ([ByteString])) just with one level of extra parentheses. If for some reason you absolutely need to avoid parentheses (mostly as a thought exercise, I guess), you'd have to have a flipped version of intercalate: flippedIntercalate :: [ByteString] - ByteString - ByteString flippedIntercalate = flip B.intercalate flippedIntercalate [ByteString] $ B.intercalate ByteString [ByteString] of course, this is pretty contrived. -Ross On Jan 5, 2009, at 1:23 PM, Galchin, Vasili wrote: yep ... that is exactly what I meant!! so can I use more $'s or must I use parens (as you did) to disambiguate? Vasili On Mon, Jan 5, 2009 at 12:18 PM, Ross Mellgren rmm- hask...@z.odi.ac wrote: Did you mean: B.intercalate (B.intercalate ByteString [ByteString]) [ByteString] ($) applies all the way to the right, so you were giving the inner intercalate two lists of ByteString. -Ross On Jan 5, 2009, at 1:17 PM, Galchin, Vasili wrote: Hi Max, That is what should happen The inner B.intercalate will produce the ByteString to be used by the B.intercalate. ?? Vasili On Mon, Jan 5, 2009 at 12:13 PM, Max Rabkin max.rab...@gmail.com wrote: 2009/1/5 Galchin, Vasili vigalc...@gmail.com: Hello, I have the following: B.intercalate $ B.intercalate ByteString [ByteString] [ByteString] I get a type error with this. If I comment out the 2nd B.intercalate and the third parameter I get no type errors. B.intercalate needs a ByteString and a list of ByteStrings. Two B.intercalates need two ByteStrings and two lists of ByteStrings. --Max ___ 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] Trouble with the ST monad
On Dec 29, 2008, at 3:43 PM, Andre Nathan wrote: On Mon, 2008-12-29 at 14:19 -0500, Ross Mellgren wrote: The problem is that you're trying to take a STMatrix from some other ST computation and freeze it in a new ST computation. The isolation between separate computations is done via the rank-2 type variable s in all those ST functions. I guess I should go and read the rank-n types page on the wiki... Try this: freezeMatrix :: (forall s . STMatrix s a) - Matrix a freezeMatrix f :: runST (freezeMatrix f) Do you know why point-free style doesn't work here even with the type annotation? I'm not very good with all the type-theoretic principles involved, but I think it's because higher ranked types cannot unify with lower ranked ones. I'm sure some of the more wizardly types could explain this with an example of how doing it like that would make something that should be illegal possible and the actual principles involved. (That's longhand for it makes a kind of intuitive sense to me but I can't explain it) Also, instead of using an array of arrays, maybe an array with (Int, Int) as the Ix might be a bit smoother? Thanks for the suggestion. It didn't occur to me that there was an Ix instance for that. Best, Andre -Ross ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Time for a new logo?
It does require a mathematical mind, but does not require that you understand the mathematical language. If mathematics are the basis of computation, and programming is an implementation of computation, then in many ways programming languages are a (less powerful) equivalent language to the language of mathematics as applied to computation. I've been professionally programming for many years, and did it as a hobby since I was very young. I'm not going to say that I'm some kind of super programmer or anything, but I have had a decent amount of programming experience in a variety of languages. That said, Haskell vexed and threw me off for a couple years before I finally sat down and tried to pull aside the curtain of mathematics terms that were (for me) obscuring how to use Haskell. Once I sat down with a ton of examples and just plodded through a bunch of research papers (it seems like all the fun features in Haskell are only described in research papers ;-) ) I saw how what I knew from the other programming languages I knew was doable in Haskell and it increased my understanding, where I can now kind-of maybe understand what those papers are talking about by relating it to how the compiler will implement the code. Of course, now that I get it, Haskell is my favorite compiled language hands-down. It was just a much longer steeper learning curve because I had to learn it and the terms used to describe it simultaneously rather than having a leg up on either from knowing other programming languages. Now, don't get me wrong, I don't think that the goal with a language should necessarily be to attract as many people as possible, but don't you feel bad for those poor sots who don't understand how bad off the mainstream of Java, C++, etc is? ;-) Just my 2 cents as a non-math-learned programmer. -Ross On Dec 16, 2008, at 7:12 AM, Malcolm Wallace wrote: Andrew Coppin andrewcop...@btinternet.com wrote: To him, apparently, the current logo says Haskell is all about arcane and obscure mathematical constructs. In fact, we think that complicated mathematics is so good that we stuffed our logo full of it. If you don't like hard math, don't even bother trying to learn this language. I think he got the right idea (kind of). To him, mathematics is arcane, but to Haskellers it is the fundamental basis of computation. If someone is not prepared to invest in learning the foundations of the subject of Computer Science, then they have no business becoming a programmer. Would you want someone who disdains mathematics to be responsible for designing the physical aerodynamics of aircraft? Then why would you permit them to program the control software that will fly it? We really must get away from the idea that programming is something any old fool should be able to pick up. Programming correct software is hard, and it requires a mathematical mind. Regards, Malcolm ___ 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