Re: [Haskell-cafe] Suggestions for an MSc Project?
Hi John I am involved in a research project of the Open University in the netherlands. We are working on a tool suite for Rule Based application developement. This is a 100% Haskell project, with lots of oppertunities for a good MSc project, depending on your specific interests. I'd be happy to talk to you about the possibilities. If you are interested, send me a mail with details how I could get in touch: han dot joosten at atosorigin dot com cheers Han. -- View this message in context: http://old.nabble.com/Suggestions-for-an-MSc-Project--tp29067884p29100221.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
Re: [Haskell-cafe] Merge hsql and HDBC -- there can only be one!
On Wed, Jul 7, 2010 at 1:16 PM, Michael Snoyman mich...@snoyman.com wrote: * I wanted the SQLite backend to be the default backend that anyone could use, without library dependencies. It would be nice if HDBC-sqlite3 had an option to build against the sqlite3 amalgamation instead of system libraries. (In fact, it would be cool if that were the default, and system libraries the option.) If only we had an RDBMS in pure Haskell :) * I'm not fond of the Convertible typeclass. In particular, it makes no distinction between conversions which are guaranteed to succeed (Int - String) and conversions which might fail (String - Int). As a result, the fromSql function can easily throw a runtime error. (For that matter, toSql could as well, but that is much less likely.) Hmm...yes, partial functions are no fun. That sounds quite unpleasant. I would probably want to make a wrapper that can catch the exception and returns an Either or Maybe type. * I would like to be able to explicitly finalize statements. I believe I've gotten some exceptions in the past when trying to close a database connection because some statements were not finalized, but I can't remember the details right now. * I don't like that the lazy versions of functions are the default, and you have to add the ' for strict. It's too easy to make mistakes with the results of a lazy database query. I would even go so far as to recommend removing them entirely, but I think most people will not like that. These last two items are reasons to use Takusen. The left fold enumerator style of Takusen means that all resource allocation can be controlled by the library, usually very precisely, and that lazy IO can be avoided. We did find one bug in the ODBC backend related to Takusen letting a finalizer run too soon, but that's fixed in the darcs repo of the Takusen sources. I've asked Alistair to release a new version of Takusen with the fix, hopefully that will happen soon. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Build problems on Hackage server
On Wed, Jul 07, 2010 at 10:22:25AM +0200, Emil Axelsson wrote: Last week I uploaded new versions of feldspar-language and feldspar-compiler. Both packages build just fine on our local machines with GHC 6.10 and 6.12. But Hackage reports the following build failure: cabal: dependencies conflict: ghc-6.12.2 requires array ==0.3.0.1 however array-0.3.0.1 was excluded because ghc-6.12.2 requires array ==0.3.0.0 Any idea of what might be causing this? I think the problem was that containers-0.3.0.0 had been rebuilt (using array-0.3.0.1, which released at the same time as GHC 6.12.3). Upgrading to GHC 6.12.3 has fixed this (until the next GHC release). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Transformers versus monadLib versus...
G'day all. Quoting Ertugrul Soeylemez e...@ertes.de: Do you realize at what level we are complaining? Yes, we're complaining at the level of the frustrated idealist, which is what many Haskell programmers are. Cheers, Andrew Bromage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Transformers versus monadLib versus...
On 8 July 2010 17:07, a...@spamcop.net wrote: G'day all. Quoting Ertugrul Soeylemez e...@ertes.de: Do you realize at what level we are complaining? Yes, we're complaining at the level of the frustrated idealist, which is what many Haskell programmers are. So true... :-( /me is still upset that reading a file requires IO... :p -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Build problems on Hackage server
2010-07-08 09:01, Ross Paterson skrev: On Wed, Jul 07, 2010 at 10:22:25AM +0200, Emil Axelsson wrote: Last week I uploaded new versions of feldspar-language and feldspar-compiler. Both packages build just fine on our local machines with GHC 6.10 and 6.12. But Hackage reports the following build failure: cabal: dependencies conflict: ghc-6.12.2 requires array ==0.3.0.1 however array-0.3.0.1 was excluded because ghc-6.12.2 requires array ==0.3.0.0 Any idea of what might be causing this? I think the problem was that containers-0.3.0.0 had been rebuilt (using array-0.3.0.1, which released at the same time as GHC 6.12.3). Upgrading to GHC 6.12.3 has fixed this (until the next GHC release). Cool, thanks! / Emil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] use of modules to save typing
I'm fairly beginnerish to Haskell, and come from OO. I have a complaint about Haskell, but I think I found a good solution. Any suggestions welcome. I have RSI and like to minimize typing. The use of classes as name spaces helps to do that. Also I can use some Emacs abbreviation magic easily with OO and not so easily with Haskell. I'll explain in a second. In Haskell, when defining data for complex programs I like to use named fields to allow for changing data definitions without having to change all code. But named fields are top-level functions (I think). They must be chosen not to clash. My habit has been to prefix them with the name of the constructor. So in a program for playing back musical documents that needs to track some state, we have: data PlayState = PlayState { playState_cursor :: Int , playState_verts :: [Loc] , playState_len :: Int , playState_doc :: MusDoc } Note all these playState_ prefixes. Lots of typing, which is not good. In OO, you could type x.cursor() In Haskell you have to type playState_cursor x which also, I feel, is harder to read. Now suppose I want to use PlayState with a State monad. -- Increment the cursor. incrCursor :: State PlayState () incrCursor = cur - gets playState_cursor len - gets playState_len let newCur = min (cur+1) (len-1) p - get put $ p {playState_cursor = newCur} Okay, I'm sorry, that is just a lot of typing for what it is doing. Not good for people with RSI, and not all that readable. I could define a function to make modifying the state a little easier. playState_update_cursor :: Int - PlayState - PlayState playState_update_cursor i p = p {playState_cur=i} Then incrCursor would look like: incrCursor :: State PlayState () incrCursor = cur - gets playState_cursor len - gets playState_len let newCur = min (cur+1) (len-1) modify (playState_update_cursor newCur) Notice how often the characters playState_ get typed. This would be a great situation for Emacs abbreviations. When you define an abbreviation in Emacs, such as defining xps to expand to PlayState, emacs will watch for the characters xps. It will then replace xps with PlayState when you type a non-alphanumeric character following xps. So if I type xps. the moment I hit . it changes to PlayState. But I would have a hard time using this feature with playState_ because it is always followed by an alphanumeric character. So my idea, now, is to put the definition of PlayState in its own module and import it qualified as PlayState. module PlayState -- data PlayState = PlayState { cursor :: Int , verts :: [Loc] , len :: [Int] , doc :: MusDoc } update_cursor i p = p {cursor = i} --- I got rid of the playState_ prefixes because I am not worried about using generic field names like doc. They won't clash if I always import this qualified. And that reduces the necessary typing in the definition. Now my monad looks like testMonad = do cursor - gets PlayState.cursor len- gets PlayState.len let newCur = min (cur+1) (len-1) modify $ PlayState.update_cursor newCur Now I can define an abbreviation for PlayState. This is a big help. Also, I find this more readable. To me PlayState.cursor is more readable than playState_cursor For one thing, syntax highlighting helps in the former case. For another, the latter case requires that you recognize a naming convention, but the former case says clearly: cursor is within the namespace PlayState, so this combination must be describing a cursor related to PlayState. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
Michael Mossey wrote: incrCursor :: State PlayState () incrCursor = cur - gets playState_cursor len - gets playState_len let newCur = min (cur+1) (len-1) modify (playState_update_cursor newCur) Whoa, I just realized I'm not using 'modify' to full advantage. This can be written incrCursor = modify incrCursor' incrCursor' (PlayState cursor len verts doc) = PlayState (min (cursor+1)(len - 1)) len verts doc) Hmm, I'm already feeling better about the State monad. Additional question: what is proper terminology here? incrCursor is a monad incrCursor is a monadic function incrCursor is a monadic type State is a monad State is a type constructor of a monad State is a monadic type incrCursor is a monadic computation Thanks, Mike ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
Michael Mossey wrote: incrCursor :: State PlayState () Additional question: what is proper terminology here? Proper terminology for monadic things is somewhat debated. incrCursor is a monad This is not true. incrCursor is a monadic type incrCursor is not a type, so this can't be correct. However, incrCursor has a monadic type is somewhat reasonable. However, I would avoid it because it is quite vague. incrCursor is a monadic function incrCursor is a monadic computation These sound good to me. I would prefer the latter, because incrCursor does not take any arguments, so it is debatable whether it is a function. From my point of view, monadic functions should mean a function of type (a - m b) where m is a monad, i.e. arrows in a Kleisli category. An alternative to monadic computation would be monadic action. However, since we know which monad it is, I would prefer incrCursor is a state transformer or even incrCursor is a PlayState transformer. State is a monad State is a type constructor of a monad State is a monadic type None of these seem to be true. However, the following is: (State PlayState) is a monad. If you want to say something about State, maybe State is a parametric monad or State is a family of monads is appropriate. Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
On 08/07/10 09:08, Michael Mossey wrote: data PlayState = PlayState { playState_cursor :: Int , playState_verts :: [Loc] , playState_len :: Int , playState_doc :: MusDoc } Notice how often the characters playState_ get typed. This would be a great situation for Emacs abbreviations. When you define an abbreviation in Emacs, such as defining xps to expand to PlayState, emacs will watch for the characters xps. It will then replace xps with PlayState when you type a non-alphanumeric character following xps. So if I type xps. the moment I hit . it changes to PlayState. But I would have a hard time using this feature with playState_ because it is always followed by an alphanumeric character. What about auto-completion? With that set of definitions, typing plexpand-key should give you playState_ (it expands to the longest unambigious expansion), and adding cexpand-key should give you playState_cursor. So you get the full thing for about five keystrokes, without any worrying about alphanumeric vs non-alphanumeric. I have completion bound to tab in emacs (a la tab completion in the shell): (global-set-key (kbd TAB) 'dabbrev-expand) and am pretty happy with this for Haskell coding. dabbrev-expand does not perform any Haskell-specific context-sensitive completion -- it just picks words out of open buffers, but I've found this to work to my satisfaction. One additional nice thing is that after a completed word, if you press space then expand-key again, it inserts the most common next word after your previous completion based on open buffers. Since in Haskell function calls and types are separated by spaces, this allows you to quickly complete common phrases from your Haskell code. Thanks, Neil. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Adding new entry to list
Hi there Jack, I have modified your program. However, where you were attempting to use direct recursion to compute totalSales, I have used functions from the prelude. I have also provided a recursive definition totalSalesRec. Here is a lesson on recursion from the Haskell wikibook http://en.wikibooks.org/wiki/Haskell/Recursion Also, what you have is an associative array which pairs (Artist, Title) with Sold. A linked list [(Artist, Title, Sold)] is an inappropriate data type for this purpose. Consider using Map from Data.Map in the form Map (Artist, Title) Sold. I have included comments which I hope you will find useful in understanding the code. Also note my use of comments like: -- | This is a function that does blah These are annotations for the Haskell documention generator, Haddock http://www.haskell.org/haddock/ What I'd do to run haddock on this file (I use linux and I have saved as artist.hs) is mkdir doc haddock artist.hs -o doc -h Now you can look at documentation for your program in a web browser while fickering with it in GHCi. Be aware that my copy pasting this file onto here may well have mangled its syntax! Have fun, Johnny module Main (main ,testDatabase ,totalSales ,totalSalesRec ,printNames ,mainLoop) where -- | Title of a record type Title = String -- | An artist, who makes records type Artist = String -- | Number of copies of a record sold type Sold = Int type Sales = [(Title, Artist, Sold)] -- | A small sales database testDatabase :: Sales testDatabase = [(Kids, MGMT, 3), (This Charming Man, The Smiths, 5), (Gimme Shelter, The Rolling Stones, 7)] -- Notice there are no explicit function arguments here. Look up 'partial application'. -- | Total sales of all records in the database. totalSales :: Sales - Sold totalSales = -- The sum of all the sales sum . map sale where sale (_,_,s) = s -- | Recursive version of totalSales totalSalesRec :: Sales - Sold totalSalesRec ((_,_,s):ss) = s + totalSalesRec ss totalSalesRec _= 0 -- | Print out the contents of a sales database printNames :: Sales - IO () printNames testDatabase = mapM_ print testDatabase -- Main application loop mainLoop :: Sales - IO () mainLoop testDatabase = do putStrLn 1 - Show all tracks in database putStrLn 2 - Show the total sales putStrLn 3 - Add a new entry putStrLn 4 - Exit putStrLn putStrLn Please select an option: input - getLine case read input of 1 - do banner Show All Tracks printNames testDatabase putStrLn mainLoop testDatabase 2 - do banner Total Sales print $ totalSales testDatabase putStrLn mainLoop testDatabase 3 - do banner New entry putStrLn Enter artist name a - getLine putStrLn putStrLn Enter title t - getLine putStrLn putStrLn Enter number of sales -- Look up functors to understand fmap s - fmap read getLine putStrLn -- 'cons' the new element to the start of the linked list testDatabase -- Look up data constructors. mainLoop $ (a,t,s) : testDatabase -- No 'do' is required for only one statement. Look up monads and how 'do' is syntactic sugar. 4 - return () where -- Print banner banner s = do putStrLn -- putStrLn s putStrLn -- -- | Run main :: IO () main = mainLoop testDatabase ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
Neil Brown wrote: On 08/07/10 09:08, Michael Mossey wrote: data PlayState = PlayState { playState_cursor :: Int , playState_verts :: [Loc] , playState_len :: Int , playState_doc :: MusDoc } Notice how often the characters playState_ get typed. This would be a great situation for Emacs abbreviations. When you define an abbreviation in Emacs, such as defining xps to expand to PlayState, emacs will watch for the characters xps. It will then replace xps with PlayState when you type a non-alphanumeric character following xps. So if I type xps. the moment I hit . it changes to PlayState. But I would have a hard time using this feature with playState_ because it is always followed by an alphanumeric character. What about auto-completion? Generally I prefer static abbreviations rather than dynamic expansion or auto-completion, because static abbreviations have predictable behavior. I'm a bit obsessive-compulsive, so I get annoyed when, say, plexpand-key expands to something shorter than I expected. With static abbreviations, behavior is 100% predictable. The abbreviations I choose, like xps follow a convention so they are easy to remember. They have no capitals. Plus the identifier before and after the period can be more generic and reusable, and in that case dynamic expansion is more reliable, or I'm more likely to benefit from defining a static abbreviation. With that set of definitions, typing plexpand-key should give you playState_ (it expands to the longest unambigious expansion), Hmm, when I use dabbrev-expand it expands to a complete identifier, but you can keep invoking it to rotate through all compatible identifiers. Maybe you are describing a mode I wasn't aware of. I do use dabbrev-expand extensively, but once an identifier becomes very common I make a static abbreviation. and adding cexpand-key should give you playState_cursor. So you get the full thing for about five keystrokes, without any worrying about alphanumeric vs non-alphanumeric. For example, as soon as I define playState_crunch then the behavior of dabbrev-expand changes. That's my complaint. I have completion bound to tab in emacs (a la tab completion in the shell): (global-set-key (kbd TAB) 'dabbrev-expand) and am pretty happy with this for Haskell coding. Interesting, so you have abandoned it for indentation... but I guess typing spaces works okay. Or do you do something else? dabbrev-expand does not perform any Haskell-specific context-sensitive completion -- it just picks words out of open buffers, but I've found this to work to my satisfaction. It does work quite well. One of the most successful dumb algorithms I know. Thanks, Mike ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Suggestions for an MSc Project?
Excerpts from John Smith's message of Sun Jul 04 10:43:17 +0200 2010: My MSc requires a project dissertation, which is expected to take about 800 hours. I would like to work on something which is of use to the Haskell community. Any suggestions? IMHO You'd make many Haskellers happy if you'd start writing something like db4o in and for Haskell. Its like a transactional database operating on objects. Marc Weber ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
From: Michael Mossey m...@alumni.caltech.edu Now my monad looks like testMonad = do cursor - gets PlayState.cursor len - gets PlayState.len let newCur = min (cur+1) (len-1) modify $ PlayState.update_cursor newCur Now I can define an abbreviation for PlayState. This is a big help. Also, I find this more readable. To me PlayState.cursor is more readable than playState_cursor For one thing, syntax highlighting helps in the former case. For another, the latter case requires that you recognize a naming convention, but the former case says clearly: cursor is within the namespace PlayState, so this combination must be describing a cursor related to PlayState. I do this as well, although I would probably import like this: import qualified PlayState as PS which then allows for PS.cursor John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Transformers versus monadLib versus...
Ivan Miljenovic ivan.miljeno...@gmail.com wrote: On 8 July 2010 13:48, Ertugrul Soeylemez e...@ertes.de wrote: Ivan Miljenovic ivan.miljeno...@gmail.com wrote: mtl's advantages: wide pre-existing user base, etc. As said, I don't think this is a valid argument. Windows has a much larger user base than Linux. C++ has a much larger user base than Haskell. We still use Haskell, and many of us use Linux. My point was, was that if you need to pick a monad transformer library and you've never done any before, then some people are likely to choose mtl because it's currently the most-used library, it comes with the platform and if they need to interact with another package that uses a monad transformer library then it's more likely to be using mtl than anything else. Yes, that's true. And my point is that that doesn't mean you shouldn't use anything else. transformers (especially when used with monads-{fd,tf}) advantage over monadLib: pre-existing type aliases, documentation, easier to port old code that was using mtl. If you don't use monadLib-specific features, then most code will run in monadLib as well as transformers without changes. The Haddock documentation of monadLib is quite brief, but if you know how to use monad transformers, you won't have any problems. I for one don't know how to use monad transformers (I mean, I've read the section in RWH and could figure it out, but off the top of my head I can't recall how to do all the lifting stuff, etc.). They are easy to use and very useful, especially to make code more modular. You should try them out. And I don't know what you mean by pre-existing type aliases. http://hackage.haskell.org/packages/archive/transformers/0.2.1.0/doc/html/Control-Monad-Trans-State-Lazy.html#t%3AState MonadLib has newtypes instead of type aliases for them. But the implementations are the same (M = MT Id). Interestingly I need transformers much more often than ready-made monads. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife = sex) http://ertes.de/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] C9 video on monads and coordinate systems
On Wed, Jul 7, 2010 at 8:00 PM, Greg Meredith lgreg.mered...@biosimilarity.com wrote: Dear Haskellians, You may be interested in this video i did with Brian Beckman on monads, location and coordinate systems. Great, nice jamming! I wonder what's the URL of the Haskell code you have, however :). Cheers, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Transformers versus monadLib versus...
Ertugrul Soeylemez e...@ertes.de writes: Ivan Miljenovic ivan.miljeno...@gmail.com wrote: My point was, was that if you need to pick a monad transformer library and you've never done any before, then some people are likely to choose mtl because it's currently the most-used library, it comes with the platform and if they need to interact with another package that uses a monad transformer library then it's more likely to be using mtl than anything else. Yes, that's true. And my point is that that doesn't mean you shouldn't use anything else. You shouldn't, but if someone comes along and has never used one of these before, which are they most likely to use? The one that seems to be most popular and is recommended in that it's in the platform or one of the other ones with less publicity but is meant to be technically superior? I for one don't know how to use monad transformers (I mean, I've read the section in RWH and could figure it out, but off the top of my head I can't recall how to do all the lifting stuff, etc.). They are easy to use and very useful, especially to make code more modular. You should try them out. I write stuff dealing with graphs; not much monadic stuff happening there ;-) And I don't know what you mean by pre-existing type aliases. http://hackage.haskell.org/packages/archive/transformers/0.2.1.0/doc/html/Control-Monad-Trans-State-Lazy.html#t%3AState MonadLib has newtypes instead of type aliases for them. But the implementations are the same (M = MT Id). Interestingly I need transformers much more often than ready-made monads. You can use newtypes instead of aliases with transformers as well (well, actually you'd need monads-{tf,fd} to get the class, but still...). My point is, is that with a type alias it's a lot easier to get up and go and start hacking without having to explicitly do StateT s Identity a all the time and instead just use State s a. Whilst technical superiority is good, a low barrier to entry (including good documentation) is just as good, and at times better. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] bug in ghci ?
Hi, I just noticed that in ghci: data Test = Test String instance Show Test show $ Test Hello Will result in infinite recursion. Is this a known bug? Thanks, titto ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
On Thursday 08 July 2010 15:20:13, Pasqualino Titto Assini wrote: Hi, I just noticed that in ghci: data Test = Test String instance Show Test show $ Test Hello Will result in infinite recursion. Is this a known bug? It's not a bug. There are default methods in Show for show in terms of showsPrec and for showsPrec in terms of show. You need to define at least one of the two to get a working Show instance, otherwise trying to evaluate (show stuff) will lead to infinite recursion, it's the same with e.g. Eq. Might be a worthwhile feature request to let the compiler emit a warning on every instance declaration where no method is defined. Thanks, titto ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
Hi titto, You should try to give a complete list of steps which can be run to reproduce your problem. This also includes ghci --version output and maybe some info about the OS you're working on. So how you you load the code into ghci? Using ghci File.hs or :l ? In any case you want to declare the show method: -- yes, I know I should just use 'deriving (Show)' because most -- developers expect Read Show instances to work the common way -- which means they serialize and unserialize data types in a reliable -- way ... instance Show Test where show (Test s) = my show implementation of Test: Test ++ s Marc Weber ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
Thanks for the explanation. What I meant is not that is a bug that it recurses but rather the fact that the compiler will accept this incomplete definition without complaining. This problem has bitten me twice while trying to use automatic derivation of a data type in another file. In my innocence I wrote: instance Show Test rather than deriving instance Show Test I didn't notice the error as GHC seemed to be happy and then when I tried to use it: BANG! Very confusing. I suppose that Haskell has spoiled me, if it compiles I assume that it will work :-) Best, titto On 8 July 2010 14:29, Daniel Fischer daniel.is.fisc...@web.de wrote: On Thursday 08 July 2010 15:20:13, Pasqualino Titto Assini wrote: Hi, I just noticed that in ghci: data Test = Test String instance Show Test show $ Test Hello Will result in infinite recursion. Is this a known bug? It's not a bug. There are default methods in Show for show in terms of showsPrec and for showsPrec in terms of show. You need to define at least one of the two to get a working Show instance, otherwise trying to evaluate (show stuff) will lead to infinite recursion, it's the same with e.g. Eq. Might be a worthwhile feature request to let the compiler emit a warning on every instance declaration where no method is defined. Thanks, titto -- Pasqualino Titto Assini, Ph.D. http://quicquid.org/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
Pasqualino \Titto\ Assini tittoass...@gmail.com writes: Hi, I just noticed that in ghci: data Test = Test String instance Show Test show $ Test Hello Well, for starters you specify such a thing in ghci, so presumably you loaded a file with these definitions. Will result in infinite recursion. Is this a known bug? Not a bug. Let us consider the definition of the Show class: class Show a where showsPrec :: Int - a - ShowS showsPrec _ x s = show x ++ s -- | A specialised variant of 'showsPrec', using precedence context -- zero, and returning an ordinary 'String'. show :: a - String show x = shows x showList :: [a] - ShowS showList ls s = showList__ shows ls s Note that showsPrec and show are by default mutually recursive, and that all the class methods have a default definition. Thus, just saying instance Show Test like you have above is valid, but not very helpful. This is why the documentation for the Show class specifies that the minimal complete definition is either showsPrec or show: defining at least one of these will cut out of the infinite recursion loop. Of course, a better question is: why are you writing your own instance for Show? Unless your data type is complex, you should just have deriving (Show) (as well as classes such as Eq, Ord and Read) attached to your datatype definition. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Transformers versus monadLib versus...
Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: Ertugrul Soeylemez e...@ertes.de writes: Ivan Miljenovic ivan.miljeno...@gmail.com wrote: My point was, was that if you need to pick a monad transformer library and you've never done any before, then some people are likely to choose mtl because it's currently the most-used library, it comes with the platform and if they need to interact with another package that uses a monad transformer library then it's more likely to be using mtl than anything else. Yes, that's true. And my point is that that doesn't mean you shouldn't use anything else. You shouldn't, but if someone comes along and has never used one of these before, which are they most likely to use? The one that seems to be most popular and is recommended in that it's in the platform or one of the other ones with less publicity but is meant to be technically superior? A lot of people try the most popular things first, just to find out that the less popular things can have better quality. Monad transformer packages are just one example. Another example is the very language itself. I came from C++ and I wouldn't go back. I came from mtl and I wouldn't go back. Same story. After all we've got the choice, so not choosing the way most people go shouldn't be flagged as something evil. There is nothing wrong with using packages, which are not in the platform. You'll need one or the other anyway for most projects. When it comes to conflicting packages you should choose the one with the highest quality for you. Caballess portability (i.e. being in the platform) may be a quality criterion and in some cases even be more important than technical superiority. However, it is not for my projects. And even if it were, you get the 'cabal' utility with the platform, so you can install monadLib easily. I for one don't know how to use monad transformers (I mean, I've read the section in RWH and could figure it out, but off the top of my head I can't recall how to do all the lifting stuff, etc.). They are easy to use and very useful, especially to make code more modular. You should try them out. I write stuff dealing with graphs; not much monadic stuff happening there ;-) I don't use monads only when I absolutely need them. I use them almost everywhere. Note that monads don't necessarily model hidden state. There are a lot of other useful monads. =) And I don't know what you mean by pre-existing type aliases. http://hackage.haskell.org/packages/archive/transformers/0.2.1.0/doc/html/Control-Monad-Trans-State-Lazy.html#t%3AState MonadLib has newtypes instead of type aliases for them. But the implementations are the same (M = MT Id). Interestingly I need transformers much more often than ready-made monads. You can use newtypes instead of aliases with transformers as well (well, actually you'd need monads-{tf,fd} to get the class, but still...). My point is, is that with a type alias it's a lot easier to get up and go and start hacking without having to explicitly do StateT s Identity a all the time and instead just use State s a. Yes, monadLib has 'State s a', but not as a type alias like in transformers, but as a newtype. I don't know the rationale behind this design choice. Probably arbitrary. It has one drawback: you need separate running functions. I don't see any advantages. I'd probably write my own type aliases instead of using the newtypes. Whilst technical superiority is good, a low barrier to entry (including good documentation) is just as good, and at times better. That's true. However, I as a non-beginner will go with the technical superiority. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife = sex) http://ertes.de/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
Pasqualino \Titto\ Assini tittoass...@gmail.com writes: Thanks for the explanation. What I meant is not that is a bug that it recurses but rather the fact that the compiler will accept this incomplete definition without complaining. This problem has bitten me twice while trying to use automatic derivation of a data type in another file. In my innocence I wrote: instance Show Test rather than deriving instance Show Test I didn't notice the error as GHC seemed to be happy and then when I tried to use it: BANG! Very confusing. I suppose that Haskell has spoiled me, if it compiles I assume that it will work :-) As I said, there would be no error as all the methods have a definition (whether or not they make sense in this case is a different story); it will still successfully load a file if any methods don't have definitions but will provide a warning in those situations. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
Hehe, seems like a -W-mutual-recursive-default-methods option is in order. On 8 July 2010 15:47, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: Pasqualino \Titto\ Assini tittoass...@gmail.com writes: Thanks for the explanation. What I meant is not that is a bug that it recurses but rather the fact that the compiler will accept this incomplete definition without complaining. This problem has bitten me twice while trying to use automatic derivation of a data type in another file. In my innocence I wrote: instance Show Test rather than deriving instance Show Test I didn't notice the error as GHC seemed to be happy and then when I tried to use it: BANG! Very confusing. I suppose that Haskell has spoiled me, if it compiles I assume that it will work :-) As I said, there would be no error as all the methods have a definition (whether or not they make sense in this case is a different story); it will still successfully load a file if any methods don't have definitions but will provide a warning in those situations. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.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] bug in ghci ?
Well the problem is that no warnings are generated. If you have a class with some methods that do not have a default implementation and you do not provide them when defining your instance, GHC will at least politely complain. Ideally, GHC would detect that a Show instance requires one of its two functions to be declared as they are mutually recursive and complain. Is that too much to ask? Maybe it is, and I can see why ghc developers would not bother, but can we agree that if not a bug, this is at least an inconvenience ? It took me a while to determine that it was not my own code but rather the incomplete show instance that was sinking my app :-) Best, titto On 8 July 2010 14:47, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: Pasqualino \Titto\ Assini tittoass...@gmail.com writes: Thanks for the explanation. What I meant is not that is a bug that it recurses but rather the fact that the compiler will accept this incomplete definition without complaining. This problem has bitten me twice while trying to use automatic derivation of a data type in another file. In my innocence I wrote: instance Show Test rather than deriving instance Show Test I didn't notice the error as GHC seemed to be happy and then when I tried to use it: BANG! Very confusing. I suppose that Haskell has spoiled me, if it compiles I assume that it will work :-) As I said, there would be no error as all the methods have a definition (whether or not they make sense in this case is a different story); it will still successfully load a file if any methods don't have definitions but will provide a warning in those situations. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com -- Pasqualino Titto Assini, Ph.D. http://quicquid.org/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
For working with record fields inside of state monads I would recommend trying out one of these packages: lenses fclabels data-accessor (I think I'm forgetting a couple) They all have special mechanisms for working with record fields inside state monads (and have lots of other cool stuff) I'm partial to lenses (I wrote it :) ), but the others are quite good as well. Hmmm I just noticed that hackage is not generating the documentation for latest version of lenses. I shall have to find out why. In the meantime, the documentation for the 0.1.2 version is essentially the same. - Job On Thu, Jul 8, 2010 at 4:08 AM, Michael Mossey m...@alumni.caltech.eduwrote: I'm fairly beginnerish to Haskell, and come from OO. I have a complaint about Haskell, but I think I found a good solution. Any suggestions welcome. I have RSI and like to minimize typing. The use of classes as name spaces helps to do that. Also I can use some Emacs abbreviation magic easily with OO and not so easily with Haskell. I'll explain in a second. In Haskell, when defining data for complex programs I like to use named fields to allow for changing data definitions without having to change all code. But named fields are top-level functions (I think). They must be chosen not to clash. My habit has been to prefix them with the name of the constructor. So in a program for playing back musical documents that needs to track some state, we have: data PlayState = PlayState { playState_cursor :: Int , playState_verts :: [Loc] , playState_len :: Int , playState_doc :: MusDoc } Note all these playState_ prefixes. Lots of typing, which is not good. In OO, you could type x.cursor() In Haskell you have to type playState_cursor x which also, I feel, is harder to read. Now suppose I want to use PlayState with a State monad. -- Increment the cursor. incrCursor :: State PlayState () incrCursor = cur - gets playState_cursor len - gets playState_len let newCur = min (cur+1) (len-1) p - get put $ p {playState_cursor = newCur} Okay, I'm sorry, that is just a lot of typing for what it is doing. Not good for people with RSI, and not all that readable. I could define a function to make modifying the state a little easier. playState_update_cursor :: Int - PlayState - PlayState playState_update_cursor i p = p {playState_cur=i} Then incrCursor would look like: incrCursor :: State PlayState () incrCursor = cur - gets playState_cursor len - gets playState_len let newCur = min (cur+1) (len-1) modify (playState_update_cursor newCur) Notice how often the characters playState_ get typed. This would be a great situation for Emacs abbreviations. When you define an abbreviation in Emacs, such as defining xps to expand to PlayState, emacs will watch for the characters xps. It will then replace xps with PlayState when you type a non-alphanumeric character following xps. So if I type xps. the moment I hit . it changes to PlayState. But I would have a hard time using this feature with playState_ because it is always followed by an alphanumeric character. So my idea, now, is to put the definition of PlayState in its own module and import it qualified as PlayState. module PlayState -- data PlayState = PlayState { cursor :: Int , verts :: [Loc] , len :: [Int] , doc :: MusDoc } update_cursor i p = p {cursor = i} --- I got rid of the playState_ prefixes because I am not worried about using generic field names like doc. They won't clash if I always import this qualified. And that reduces the necessary typing in the definition. Now my monad looks like testMonad = do cursor - gets PlayState.cursor len- gets PlayState.len let newCur = min (cur+1) (len-1) modify $ PlayState.update_cursor newCur Now I can define an abbreviation for PlayState. This is a big help. Also, I find this more readable. To me PlayState.cursor is more readable than playState_cursor For one thing, syntax highlighting helps in the former case. For another, the latter case requires that you recognize a naming convention, but the former case says clearly: cursor is within the namespace PlayState, so this combination must be describing a cursor related to PlayState. ___ 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] bug in ghci ?
Pasqualino \Titto\ Assini tittoass...@gmail.com writes: Well the problem is that no warnings are generated. If you have a class with some methods that do not have a default implementation and you do not provide them when defining your instance, GHC will at least politely complain. Ideally, GHC would detect that a Show instance requires one of its two functions to be declared as they are mutually recursive and complain. So you're volunteering to write such functionality? :p -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
On 8 July 2010 15:11, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: So you're volunteering to write such functionality? :p No ! I will patiently wait for the Simons' Dream Team to fix that and in the meantime I will live with the realisation that, having been kicked out of Eden, there is nothing in this world that is absolutely perfect, not even Haskell. Thanks again to everybody for their prompt answers, I had almost forgotten how reactive and comprehensive this mailing list can be :-) titto ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Merge hsql and HDBC -- there can only be one!
I'd love to see this too. I've only used HDBC and I think it works well. A common problem in the Haskell-community is that some produce low-level bindings/libs and some produce high-level (extremely type safe) bindings/libs but there's seldom good support for switching between or combining the two approaches. My experience is that when it comes to real world scenarios involving databases/xml/json/c you are seldom able to figure out *all* types compile time and are thus forces to use the low-level lib for everything even though you got the types (e.g. of a table/view/function/...) at compile time for 90% of your code. That's a shame and something that I wish a merging between the packages would be able to solve. In other words: a good package should support more than one way to interface with the db and the different ways should be possible to seamlessly combine. My wish-list: * low level capabilities a la HDBC * high level capabilities (matching result sets to data types, db functions - haskell type classes or similar) * sql 2003/2008-, pl/sql-quasi quoter * code generation given a db schema. * schema generation from code (i.e. the opposite from the above). * fixture generation (Haskell - db, db - Haskell) * syb-support * BSD3 or DWTFYWT * github :) I'm prepared to spend a couple of hours a week helping out and I got some experience developing database layers that's used in telecom, gaming and logistics. -- Oscar P.S. I'm not saying that there should be only one; competition is always good. It would however be lovely if the community made an effort to (a) produce an package that can cover mosts needs that (b) most developers/package-maintainers used that (c) other developers can build upon with new features. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
On Thursday 08 July 2010 16:11:58, Ivan Lazar Miljenovic wrote: Pasqualino \Titto\ Assini tittoass...@gmail.com writes: Well the problem is that no warnings are generated. If you have a class with some methods that do not have a default implementation and you do not provide them when defining your instance, GHC will at least politely complain. Ideally, GHC would detect that a Show instance requires one of its two functions to be declared as they are mutually recursive and complain. So you're volunteering to write such functionality? :p Well, I made the suggestion of emitting a warning on instance declarations without method definitions. That would be comparatively easy to implement (even with an additional check to only emit the warning if the class defines any methods) and catch many (if not most) cases. If somebody points me to the relevant modules, I could be persuaded to write it, even. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] C9 video on monads and coordinate systems
Dear Felipe, Thanks for your note! Here's some quick and dirty code to get the point across. data T v = Constant Bool -- just to let us get off the ground... | Mention v | Abstraction [v] (T v) | Application (T v) (T v) deriving (Eq, Show) data RN t = RN ( t, [((RN t), t)] ) deriving (Eq, Show) data RT = RT (T (RN RT)) deriving (Eq, Show) Best wishes, --greg On Thu, Jul 8, 2010 at 6:15 AM, Felipe Lessa felipe.le...@gmail.com wrote: On Wed, Jul 7, 2010 at 8:00 PM, Greg Meredith lgreg.mered...@biosimilarity.com wrote: Dear Haskellians, You may be interested in this video i did with Brian Beckman on monads, location and coordinate systems. Great, nice jamming! I wonder what's the URL of the Haskell code you have, however :). Cheers, -- Felipe. -- L.G. Meredith Managing Partner Biosimilarity LLC 1219 NW 83rd St Seattle, WA 98117 +1 206.650.3740 http://biosimilarity.blogspot.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
On Thu, Jul 8, 2010 at 3:45 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: Well, I made the suggestion of emitting a warning on instance declarations without method definitions. That would be comparatively easy to implement (even with an additional check to only emit the warning if the class defines any methods) and catch many (if not most) cases. Unfortunately, it would catch some perfectly valid cases, see the list of instances for flat datatypes here: http://hackage.haskell.org/packages/archive/deepseq/1.1.0.0/doc/html/src/Control-DeepSeq.html This demonstrates that there is at least one (admittedly probably not much more than one) case where a class with methods would have a default implementation that was total and valid in some cases. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Transformers versus monadLib versus...
Hi Edward, Edward Kmett wrote: It looks like there is a fairly strong effort to fix most of the most egregious warts in the mtl. btw, does this overhaul include adding Applicative instances, perchance? Thanks, Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] bug in ghci ?
On Thursday 08 July 2010 18:24:05, Ben Millwood wrote: On Thu, Jul 8, 2010 at 3:45 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: Well, I made the suggestion of emitting a warning on instance declarations without method definitions. That would be comparatively easy to implement (even with an additional check to only emit the warning if the class defines any methods) and catch many (if not most) cases. Unfortunately, it would catch some perfectly valid cases, see the list of instances for flat datatypes here: http://hackage.haskell.org/packages/archive/deepseq/1.1.0.0/doc/html/src /Control-DeepSeq.html This demonstrates that there is at least one (admittedly probably not much more than one) case where a class with methods would have a default implementation that was total and valid in some cases. Good point. So one should check for more than one class-method [then defining no methods in the instance declaration is likely to lead to a default-method loop if there are default methods for all, otherwise GHC will warn already]. That can of course still give rise to spurious warnings, but is less likely to. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What is Haskell unsuitable for?
On Tue, 6 Jul 2010, Edward Kmett wrote: While we're on the topic, does anyone else get funny looks when they say monads? Sadly, yes. ;) There is no need anymore to bother people with the word monad: http://www.haskell.org.monadtransformer.parallelnetz.de/haskellwiki/Category:Monad ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
Hello all For manipulating records I use an arity family of so-called Starling combinators - they seem a pleasant if low-powered solution. To me, the infix combinator style of Data-Accessor quickly ends up looking like a particulary angry exchange between Snoopy and Woodstock[1]. star :: (a - r - ans) - (r - a) - r - ans star2 :: (a - b - r - ans) - (r - a) - (r - b) - r - ans star3 :: (a - b - c - r - ans) - (r - a) - (r - b) - (r - c) - r - ans star4 :: (a - b - c - d - r - ans) - (r - a) - (r - b) - (r - c) - (r - d) - r - ans star5 :: (a - b - c - d - e - r - ans) - (r - a) - (r - b) - (r - c) - (r - d) - (r - e) - r - ans star f fa x = f (fa x) x star2 f fa fb x = f (fa x) (fb x) x star3 f fa fb fc x= f (fa x) (fb x) (fc x) x star3 f fa fb fc fd x = f (fa x) (fb x) (fc x) (fd x) x An example - tracking the source position in a parser: data SrcPos = SrcPos { src_line :: Int, src_column :: Int, src_tab_size :: Int } incrCol :: SrcPos - SrcPos incrCol = star (\i s - s { src_column=i+1 }) src_column incrTab :: SrcPos - SrcPos incrTab = star2 (\i t s - s { src_column=i+t }) src_column src_tab_size incrLine :: SrcPos - SrcPos incrLine = star (\i s - s { src_line =i+1, src_column=1 }) src_line [1] For those missing the cultural reference, in the UK and USA cartoon characters usually have swearing censored with sequences of non-alpha characters, e.g. What the @#*! ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Code Example and Haskell Patterns
Hi, Hackage is a sizable repository of Haskell code; makes me wonder if there is a way to use it more effectively for pedagogical purposes. For example, I really would like to study State monad, monad transformers, applicative, arrows etc. in action--i.e., in the context of a real application rather than small toy examples commonly found in tutorials. If there isn't such a source, can someone point me to an application whose implementation you would consider being a paragon for said concepts? Best, Ali ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Code Example and Haskell Patterns
ali.razavi: Hi, Hackage is a sizable repository of Haskell code; makes me wonder if there is a way to use it more effectively for pedagogical purposes. For example, I really would like to study State monad, monad transformers, applicative, arrows etc. in action--i.e., in the context of a real application rather than small toy examples commonly found in tutorials. If there isn't such a source, can someone point me to an application whose implementation you would consider being a paragon for said concepts? xmonad uses monad transformers in a canonical fashion, IMO. For applicatives, some of the parser combinator libraries, like cereal, provide good use. You can follow the reverse dependencies to find packages that use things you're interested in: http://bifunctor.homelinux.net/~roel/cgi-bin/hackage-scripts/revdeps/arrows-0.4.2.0#direct -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Code Example and Haskell Patterns
Hello I suspect you will have to choose single examples for each of the patterns/ abstractions you are interested in. Doaitse Swierstra's library UU.Parsing is the originator or the Applicative style. Its latest incarnation is the library uu-parsinglib. There is extensive technical report detailing it: http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-044.pdf http://hackage.haskell.org/package/uu-parsinglib ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Haskell-Cafe Digest, Vol 83, Issue 25
WHUSSUP? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: Haskell 2010 Report (final)
On Tue, Jul 06, 2010 at 09:48:20PM +0300, Roman Cheplyaka wrote: Greetings! Now, can different compiler/interpreter authors make statements about support of this standard in their compilers please? Jhc supports all the language features of haskell 2010 except pattern guards. (ironic as I am a huge fan of said feature.) The library situation is more complicated, there is tension between haskell 98, haskell 2010, and supporting code in the wild, which often assumes some specific version of ghc's base, which doesn't quite conform to either. My current thinking is to give up supporting base directly as a clone of ghc's and rather support just haskell 98 and haskell 2010 modes natively, then compatability libraries (called things like ghc-base-4 and ghc-base-3 perhaps) would be independent projects and not tied to jhc releases. jhc 0.7.4 which supports garbage collection and a speedier runtime and better support for external build systems will be out soon. My goal is one more point release before 0.8.0 which will have full haskell 2010 and 98 support. John -- John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Merge hsql and HDBC -- there can only be one!
On the subject of bridging relational persistence and fucntional programming I wish to communicate on what I'm working on (Tránsito Abierto Library) (or Open Transit): 1) Whole objective: To disminish to gap between functional and relational paradigms. 2) Specific objetive: Illustrate and explore the gap. 3) Narrow focus: I'm using Takusen and Oracle and Haskell (á la GHC). And Template Haskell (TH). 4) Hypothesis: There'll be always a gap because you're using distinct nature beasts, but you a bit more of convinience would yield great improvements. 4.1) Another thought on this is: A mapping always needs to be specified between data shapes (types/representations). 5) Findings/Achievements(?): 5.1) Generation of Haskell types and iterator code given the shape of relational table. This is not very useful itself. Because of (4.1), using SQL is an effective way to: (1) convey such mapping and (2) specify queries that involve more than one table. 5.2) Given a sql query text, use the facilities on Oracle database to describe the query. With such description, use Template Haskell to generate Haskell types and iterator code. Let us call Geco to this generated code that is built by means of an AST. 5.3) As 5.2 (spliced Geco) but saving the Geco AST. What for? It turns out that later, during program execution you can regenerate a fresh AST code and compare it to Geco AST. If there's a difference it means your database environment is changed and it is likely that your code is no longer safe. The idea here, your program reacts to the enviroment detecting if its unsafe to run. 5.4) Takusen covers many database datatypes but not all. 5.5) I was about to automate pl/sql bindings using a inspired Takusen wrapper found on the enumerator tests directory . It follows scheme 5.2. But it is uncomplete. 5.6) Takusen is limited to iterators up to 8 fields. By using TH, easily you can have any number of columns in your query. 5.7) I wrote a serialiser library on the DB side and a deserialiser library on Haskell side. The idea it's to push *any* pl/sql result onto a string and recover it on the Haskell side. Needs schemes 5.2 and 5.5 to work. Status: Not working. 6) I believe intelligent schema generation is possible following the scheme above. What you would get is a whole module that would enforce constraints (cardinality, restrictions, etc). 7) I haven't try the way Haskell - DB. Neither the storing of functional values as it was done before in Persistent Haskell and others. Cheers, -- Leonel Fonseca. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Memoization in Haskell?
Hi, I'm going through the first chapters of the Real World Haskell book, so I'm still a complete newbie, but today I was hoping I could solve the following function in Haskell, for large numbers (n 108) f(n) = max(n,f(n/2)+f(n/3)+f(n/4)) I've seen examples of memoization in Haskell to solve fibonacci numbers, which involved computing (lazily) all the fibonacci numbers up to the required n. But in this case, for a given n, we only need to compute very few intermediate results. How could one go about solving this efficiently with Haskell? Thanks in advance, Ángel de Vicente -- http://www.iac.es/galeria/angelv/ High Performance Computing Support PostDoc Instituto de Astrofísica de Canarias - ADVERTENCIA: Sobre la privacidad y cumplimiento de la Ley de Protección de Datos, acceda a http://www.iac.es/disclaimer.php WARNING: For more information on privacy and fulfilment of the Law concerning the Protection of Data, consult http://www.iac.es/disclaimer.php?lang=en ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memoization in Haskell?
On Thursday 08 July 2010 23:30:05, Angel de Vicente wrote: Hi, I'm going through the first chapters of the Real World Haskell book, so I'm still a complete newbie, but today I was hoping I could solve the following function in Haskell, for large numbers (n 108) f(n) = max(n,f(n/2)+f(n/3)+f(n/4)) You need some base case or you'll have infinite recursion. I've seen examples of memoization in Haskell to solve fibonacci numbers, which involved computing (lazily) all the fibonacci numbers up to the required n. But in this case, for a given n, we only need to compute very few intermediate results. How could one go about solving this efficiently with Haskell? If f has the appropriate type and the base case is f 0 = 0, module Memo where import Data.Array f :: (Integral a, Ord a, Ix a) = a - a f n = memo ! n where memo = array (0,n) $ (0,0) : [(i, max i (memo!(i `quot` 2) + memo!(i `quot` 3) + memo!(i `quot` 4))) | i - [1 .. n]] is wasteful regarding space, but it calculates only the needed values and very simple. (to verify: module Memo where import Data.Array import Debug.Trace f :: (Integral a, Ord a, Ix a) = a - a f n = memo ! n where memo = array (0,n) $ (0,0) : [(i, max (trace (calc ++ show i) i) (memo!(i `quot` 2) + memo!(i `quot` 3) + memo!(i `quot` 4))) | i - [1 .. n]] ) You can also use a library (e.g. http://hackage.haskell.org/package/data- memocombinators) to do the memoisation for you. Another fairly simple method to memoise is using a Map and State, import qualified Data.Map as Map import Control.Monad.State f :: (Integral a) = a - a f n = evalState (memof n) (Map.singleton 0 0) where memof k = do mb - gets (Map.lookup k) case mb of Just r - return r Nothing - do vls - mapM memof [k `quot` 2, k `quot` 3, k `quot` 4] let vl = max k (sum vls) modify (Map.insert k vl) return vl Thanks in advance, Ángel de Vicente ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memoization in Haskell?
On Friday 09 July 2010 00:10:24, Daniel Fischer wrote: You can also use a library (e.g. http://hackage.haskell.org/package/data- memocombinators) to do the memoisation for you. Well, actualy, I think http://hackage.haskell.org/package/MemoTrie would be the better choice for the moment, data-memocombinators doesn't seem to offer the functionality we need out of the box. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memoization in Haskell?
On Thu, Jul 8, 2010 at 4:23 PM, Daniel Fischer daniel.is.fisc...@web.de wrote: On Friday 09 July 2010 00:10:24, Daniel Fischer wrote: You can also use a library (e.g. http://hackage.haskell.org/package/data- memocombinators) to do the memoisation for you. Well, actualy, I think http://hackage.haskell.org/package/MemoTrie would be the better choice for the moment, data-memocombinators doesn't seem to offer the functionality we need out of the box. I'm interested to hear what functionality MemoTrie has that data-memocombinators does not. I wrote the latter in hopes that it would be strictly more powerful*. Luke * Actually MemoTrie wasn't around when I wrote that, but I meant the combinatory technique should be strictly more powerful than a typeclass technique. And data-memocombinators has many primitives, so I'm still curious. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] use of modules to save typing
On 08.07.2010 11:15, Michael Mossey wrote: Whoa, I just realized I'm not using 'modify' to full advantage. This can be written incrCursor = modify incrCursor' incrCursor' (PlayState cursor len verts doc) = PlayState (min (cursor+1)(len - 1)) len verts doc) Thats what lambdas are good for: incrCursor = modify $ \p@(PlayState c l _ _) - p { cursor = min (c+1) (l-1) } Or... incrCursor = modify $ \...@playstate { cursor = c, len = l } - p { cursor = min (c+1) (l-1) } :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Talking to Java from Haskell?
Hi, Someone has written a large Java library (QuickFIX/J) which speaks a gnarled, ugly protocol (FIX). There don't appear to be any FIX protocol libraries in Hackage. I need my Haskell program to talk to a 3rd-party system that only speaks FIX. Should I: a) Reimplement the protocol directly Haskell? (This appears to be non-trivial) b) Wrap the Java library with some code to use a lightweight message queue (zeromq) to send messages to my Haskell program? (This would require essentially re-implementing an abstracted subset of the the protocol into 0MQ messages) c) Find a way for Haskell to interact directly with Java? (the various JNI bridges seem very unmaintained...) To me, (b) seems like the best approach, but I'd like to hear what the cafe thinks.. Cheers, - Dan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Talking to Java from Haskell?
HI Dan, It depends on how much of the protocol you're going to use. If you only have to use some kinds of messages it may be fastest to use Scala and Actors using the Java library. Depending on the data I'd use a very simple protocol for the communication Haskell - Scala. Whether you should reimplement the protocol also depends on whether speed is an issue. If nobody picked up and started to work on Java interaction I think you're right that b is the fastest option. Marc Weber ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Multidimensional Matrices in Haskell
Have you considered http://hackage.haskell.org/package/hTensor ? On Wed, Jul 7, 2010 at 9:58 PM, John Lato jwl...@gmail.com wrote: Hello, There are a lot of options. The array package, which is included with GHC, provides both mutable and immutable arrays of arbitrary dimensions. A quick scan of hackage shows ArrayRef, ix-shapable, and judy as alternatives, among others. Immutable arrays can be pure, but all mutable array interfaces will require a monad of some type. I usually think ST-based mutability is easiest to work with. John From: Mihai Maruseac mihai.marus...@gmail.com Hi, A friend of mine wanted to do some Cellular Automata experiments in Haskell and was asking me what packages/libraries are there for multidimensional matrices. I'm interested in both immutable and mutable ones but I don't want them to be trapped inside a monad of any kind. Any hints? -- MM ___ 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] Talking to Java from Haskell?
On Thu, Jul 8, 2010 at 6:35 PM, Daniel Cook danielkc...@gmail.com wrote: Hi, Someone has written a large Java library (QuickFIX/J) which speaks a gnarled, ugly protocol (FIX). There don't appear to be any FIX protocol libraries in Hackage. I need my Haskell program to talk to a 3rd-party system that only speaks FIX. Should I: a) Reimplement the protocol directly Haskell? (This appears to be non-trivial) b) Wrap the Java library with some code to use a lightweight message queue (zeromq) to send messages to my Haskell program? (This would require essentially re-implementing an abstracted subset of the the protocol into 0MQ messages) c) Find a way for Haskell to interact directly with Java? (the various JNI bridges seem very unmaintained...) Are you referring to projects like these? * lambdaVM: http://www.cs.rit.edu/~bja8464/lambdavm/ * EclipseFP uses (or used, I'm not sure) a bridge between Java/Haskell. I doubt these approaches are very mature for general purpose work. They probably work well for the author's original purpose, but perhaps you'd run into low level bugs using them yourself. I assume they use Java's JNI and connect that to Haskell FFI. I don't know why this would be a necessarily hard problem. Haskell's FFI is very nice for talking to C, but perhaps Java's JNI is not as friendly. I would probably start by writing a JNI wrapper around QuickFIX to expose it to C and C-like languages. Then I would write a Haskell FFI binding to that library. In this way, C will become your glue language as odd as that may sound. As a longer term solution, having a combinator library for FIX in Haskell sounds really nice. I don't need it personally, but it just seems like the way to go. The drawback here is that you will have to duplicate a lot of effort to keep your implementation in sync with the de facto implementation. On the other hand, depending on the nature of the technical hurdles your Haskell implementation may be significantly easier to maintain and could possibly end up serving as a concise, correct, reference implementation when the FIX specification changes. It's also possible that some Haskell compiler, such as YHC, would serve well here. Maybe it's easier to modify that in the way lambdaVM is a modification to GHC. If I recall correctly, YHC had a backend for JavaScript at one point. That makes me think it has a very hackable backend. Another possibility that tends to work very well is to use Haskell to define a domain specific language. Your DSL could generate Java source that uses QuickFIX directly. You get the strength of using the de facto tool chain for your production binaries, the power of Haskell for language design, and the expressive power that comes from having a domain specific language. This solution is also cheaper than it might sound. You start with combinators that build up Java expressions and go from there. It's hard for me to say which is best without knowing more about the programs you'll be writing. Sounds like an interesting project! Good luck, Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Talking to Java from Haskell?
I would probably start by writing a JNI wrapper around QuickFIX to expose it to C and C-like languages. Then I would write a Haskell FFI binding to that library. In this way, C will become your glue language as odd as that may sound. vs. Depending on the data I'd use a very simple protocol for the communication Haskell - Scala. The JNI thing would probably run very fast. Given my total ignorance of JNI and Haskell FFI, it could be challenging to implement, however. In some ways, this suggestion encourages me even more to use a message queue: people have already implemented the messaging interface for both Haskell and Java, so that all I need to do is specify some messages. I should make it clear: my objective is to do the minimal amount of engineering necessary to get the data from FIX messages into my Haskell program. As a longer term solution, having a combinator library for FIX in Haskell sounds really nice. I don't need it personally, but it just seems like the way to go. It does - but I think sounds really nice [...] it just seems like the way to go is exactly what my professors meant by mission creep in all those software engineering classes. Doesn't using an existing Scala Haskell libraries to generate parse e.g. lightweight JSON messages also seem elegant? Another possibility that tends to work very well is to use Haskell to define a domain specific language. Woah. Lateral thinking. In some ways, Jaskell has already done this. On Fri, Jul 9, 2010 at 2:58 AM, Jason Dagit da...@codersbase.com wrote: On Thu, Jul 8, 2010 at 6:35 PM, Daniel Cook danielkc...@gmail.com wrote: Hi, Someone has written a large Java library (QuickFIX/J) which speaks a gnarled, ugly protocol (FIX). There don't appear to be any FIX protocol libraries in Hackage. I need my Haskell program to talk to a 3rd-party system that only speaks FIX. Should I: a) Reimplement the protocol directly Haskell? (This appears to be non-trivial) b) Wrap the Java library with some code to use a lightweight message queue (zeromq) to send messages to my Haskell program? (This would require essentially re-implementing an abstracted subset of the the protocol into 0MQ messages) c) Find a way for Haskell to interact directly with Java? (the various JNI bridges seem very unmaintained...) Are you referring to projects like these? * lambdaVM: http://www.cs.rit.edu/~bja8464/lambdavm/ * EclipseFP uses (or used, I'm not sure) a bridge between Java/Haskell. I doubt these approaches are very mature for general purpose work. They probably work well for the author's original purpose, but perhaps you'd run into low level bugs using them yourself. I assume they use Java's JNI and connect that to Haskell FFI. I don't know why this would be a necessarily hard problem. Haskell's FFI is very nice for talking to C, but perhaps Java's JNI is not as friendly. I would probably start by writing a JNI wrapper around QuickFIX to expose it to C and C-like languages. Then I would write a Haskell FFI binding to that library. In this way, C will become your glue language as odd as that may sound. As a longer term solution, having a combinator library for FIX in Haskell sounds really nice. I don't need it personally, but it just seems like the way to go. The drawback here is that you will have to duplicate a lot of effort to keep your implementation in sync with the de facto implementation. On the other hand, depending on the nature of the technical hurdles your Haskell implementation may be significantly easier to maintain and could possibly end up serving as a concise, correct, reference implementation when the FIX specification changes. It's also possible that some Haskell compiler, such as YHC, would serve well here. Maybe it's easier to modify that in the way lambdaVM is a modification to GHC. If I recall correctly, YHC had a backend for JavaScript at one point. That makes me think it has a very hackable backend. Another possibility that tends to work very well is to use Haskell to define a domain specific language. Your DSL could generate Java source that uses QuickFIX directly. You get the strength of using the de facto tool chain for your production binaries, the power of Haskell for language design, and the expressive power that comes from having a domain specific language. This solution is also cheaper than it might sound. You start with combinators that build up Java expressions and go from there. It's hard for me to say which is best without knowing more about the programs you'll be writing. Sounds like an interesting project! Good luck, Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Comments on Haskell 2010 Report
based upon final version PDF created 7/6/2010 11:44:27 1. I.E. and e.g. should be followed by commas -- unless UK usage differs from US standards. (Page 3 and elsewhere, although FFI chapter seems to have the commas.) Also, inconsistent mix of British and American usage throughout (-ize and -ise, flavour, behaviour, behavior, analyse, color, colour, finaliser, finalizer, etc.) 2. Inconsistent spelling (lowercase/uppercase in section 1.4; lower-case/upper-case in section 2.4) 3. In section 3.11, boolean misspelled boolen. 4. LaTeX macros involving @ showing up in text. See sects 3.12, 6.4.2, 11.1, and in Chapter 9. 5. In section 3.15.2, reference to third bullet seems like it should be fourth bullet. 6. In section 3.17.2, the example that is supposed to return [undefined,undefined,undefined] seems like it really ought to return undefined, although I can see in the description above for ~apat matching where the other interpretation would hold. I actually tried this in GHC 10.4.2, binding the result to a variable and then applying the function length to it, and it comes back with undefined, whereas performing length [undefined,undefined,undefined] returns 3. So it appears that in this case, at least GHC 10.4.2 is returning undefined rather than [undefined,undefined,undefined]. 7. In section 6.3.4, [LT..] needs whitespace in the middle to parse correctly. 8. I'm curious about last part of section 6.4.3 that says 0**y is undefined. It seems to work reasonably under GHC, returning 0 in every case except 0**0, which returns 1 (the ^0 == 1 rule taking precedence, apparently.) Saying 0**0 is undefined seems reasonable, but why 0**y? 9. In section 6.4.6, statement about b^(d-1) = m b^d doesn't seem to hold when m 0. Should it be |m| in the equation, rather than m? 10. Section 7.1 uses function in places where it ought to use action. It seems more correct to describe print as returning an action that outputs a value. Most of the Input Functions (e.g., getChar, getLine, getContents, readLn) should be described as actions, not functions. It switches to using the term operation, which seems better, but then reverts back to function. 11. In section 8.4, variable misspelled varibale. 12. In section 8.5.1, in we require that chname ends on .h, on should be in. 13. Also in section 8.5.1, dependent misspelled dependant. 14. Last paragraph of section 8.5,1 has extra a -- ... defined to a accept a Following sentence has a semicolon where it should have a comma. 15. In section 10.3, (i.e. the programmer... has no closing paren. 16. In section 10.4, ... other lines are comment, comments sounds better. This occurs twice. 17. Also in section 10.6, anything misspelled anyything. 18. In Chapter 15, it would be more clear to describe bit i as producing a value with the ith bit set, and all other bits clear. 19. In section 20.3.1, caveats about finiteness of lists similar to ones given for and and or could also apply to any and all. Ditto for elem, notElem, etc. Maybe a single paragraph could summarize this short-circuiting behavior for all of them. 20. In heading for 20.9.2, quotes around Set are not balanced. Both are closing quotes. Ditto for 20.10.1, 20.10.2. 21. In section 29.1.1, finaliser and finalizer used in same paragraph. 22. In section 38.2, first occurrence of 'dual' has mismatched quotes. 23. In section 41.1, quotes around perform are mismatched. Word function is mildly misused again here. 24. In section 41.3.1, it would be nice to document what happens if act terminates abnormally, and then a secondary exception occurs during the closing of the handle. Oftentimes systems lose the primary exception and propagate out the secondary exception, whereas in reality we may be more interested in the original primary exception. 25. In section 41.4.4, bullet before isPermissionError isn't rendered correctly. Alex ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Talking to Java from Haskell?
Daniel Cook wrote: b) Wrap the Java library with some code to use a lightweight message queue (zeromq) to send messages to my Haskell program? (This would require essentially re-implementing an abstracted subset of the the protocol into 0MQ messages) A simpler solution might be Facebook's thrift [1] (now an Apache project). You write a simple file in a C-inspired IDL which gives typedefs and RPC signatures, and not only do you get the data structures and serialization functions in a number of target languages including Haskell and Java, but you get lightweight, relatively robust, server and client implementations. The implementations of the Java functions can then be written in Scala or Clojure, so you avoid having to leave fp-land entirely. One could even run the Java binary directly from Haskell using System.Process and friends, and rather than communicating over ports, communicate over pipes. In any case, I've had good luck with this approach. Cheers, Sterl. [1] http://incubator.apache.org/thrift/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memoization in Haskell?
Daniel Fischer wrote: If f has the appropriate type and the base case is f 0 = 0, module Memo where import Data.Array f :: (Integral a, Ord a, Ix a) = a - a f n = memo ! n where memo = array (0,n) $ (0,0) : [(i, max i (memo!(i `quot` 2) + memo!(i `quot` 3) + memo!(i `quot` 4))) | i - [1 .. n]] is wasteful regarding space, but it calculates only the needed values and very simple. Can someone explain to a beginner like me why this calculates only the needed values? The list comprehension draws from 1..n so I don't understand why all those values wouldn't be computed. Thanks Mike ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Memoization in Haskell?
On 7/8/10 9:17 PM, Michael Mossey wrote: Daniel Fischer wrote: If f has the appropriate type and the base case is f 0 = 0, module Memo where import Data.Array f :: (Integral a, Ord a, Ix a) = a - a f n = memo ! n where memo = array (0,n) $ (0,0) :[(i, max i (memo!(i `quot` 2) + memo!(i `quot` 3) + memo!(i `quot` 4))) | i - [1 .. n]] is wasteful regarding space, but it calculates only the needed values and very simple. Can someone explain to a beginner like me why this calculates only the needed values? The list comprehension draws from 1..n so I don't understand why all those values wouldn't be computed. The second pair of each element of the list will remain unevaluated until demanded --- it's the beauty of being a lazy language. :-) Put another way, although it might look like the list contains values (and technically it does due to referential transparency), at a lower level what it actually contains are pairs such that the second element is represented not by number but rather by a function that can be called to obtain its value. Cheers, Greg ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Multidimensional Matrices in Haskell
On Fri, Jul 9, 2010 at 4:50 AM, Daniel Cook danielkc...@gmail.com wrote: Have you considered http://hackage.haskell.org/package/hTensor ? On Wed, Jul 7, 2010 at 9:58 PM, John Lato jwl...@gmail.com wrote: Hello, There are a lot of options. The array package, which is included with GHC, provides both mutable and immutable arrays of arbitrary dimensions. A quick scan of hackage shows ArrayRef, ix-shapable, and judy as alternatives, among others. Immutable arrays can be pure, but all mutable array interfaces will require a monad of some type. I usually think ST-based mutability is easiest to work with. John From: Mihai Maruseac mihai.marus...@gmail.com Hi, A friend of mine wanted to do some Cellular Automata experiments in Haskell and was asking me what packages/libraries are there for multidimensional matrices. I'm interested in both immutable and mutable ones but I don't want them to be trapped inside a monad of any kind. Any hints? Thanks for the input. Will test all of them :) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] does () match with a??
Hey! I just wanted to let you know I made it. I just changed the newtype declaration to: newtype Game r = Game { execGame :: Int - (Maybe r,Int) } and from there everything went just fine. Thank you for your responses, Hector Guilarte On Wed, Jul 7, 2010 at 9:24 PM, Hector Guilarte hector...@gmail.com wrote: On Wed, Jul 7, 2010 at 8:48 PM, John Meacham j...@repetae.net wrote: Are you sure you are interpreting what 'die' should do properly? Your code makes sense if die should decrement your life counter and continue along, however if 'die' is meant to end your whole game, then there is another implementation that does type check. John You're absolutely right, I sen't the wrong code, here's the correct one and a little bit more explanation about what checkpoint does. The result of die makes sense for the checkPoint function since there are three cases for it: 1) The player died and has no remaining lifes. The game can't continue, I just return Noting in the die function and in checkpoint make the corresponding case. 2) The player died and has remaining lifes. The game can be retried with a life subtracted. I would need to tell checkpoint that I died and I want to retry, that's where I think the result is important, because of the next case. 3) The player didn't died, it finished the particular game and checkpoint m equals m. Here I would need to see if the result of the game was different from the result from die, and continue. instance GameMonad Game where extraLife= Game $ \l - Just ((),l+1) getLives = Game $ \l - Just (l,l) die = do n - getLives if n = 0 then Game $ \_ - Nothing else Game $ \_ - Just (player died,n-1) checkPoint a = do n - getLives case execGame a n of Nothing - Game $ \_ - Nothing Just c - gameOn $ fst c where gameOn player died = a = \_ - (checkPoint a) gameOn _ = a Obviously this fails to compile because I'm returning a String and it doesn't match with a either, but the idea of what I think I need to do is right there. Ivan Miljenovic told me to use error, and actually I though something like that. in STM retry combined with atomically does something similar as what I need checkpoint and die to do, and they use exceptions to accomplish it. I really think that's the solution I want, but then I have another question, when I 'throw' the exception in die and 'catch' it in checkpoint to call it again, is the number of lives gonna be lives - 1? Thanks for answering so quickly, Hector Guilarte Pd: Here's an example run of how my homework should work after is finished printLives :: ( GameMonad m , MonadIO m ) = String - m () printLives = do n - getLives liftIO $ putStrLn $ s ++ ++ show n test1 :: ( GameMonad m , MonadIO m ) = m () test1 = checkPoint $ do printLives Vidas : die liftIO $ putStrLn Ganamos ! lastChance :: GameMonad m = m () lastChance = do n - getLives if n == 1 then return () else die test2 :: ( GameMonad m , MonadIO m ) = m String test2 = checkPoint $ do printLives Inicio n - getLives if n == 1 then do liftIO $ putStrLn Final return Victoria ! else do checkPoint $ do printLives Checkpoint anidado lastChance extraLife printLives Vida extra ! die AND THE OUTPUT TO SOME CALLS ghci runGameT test1 3 Vidas : 3 Vidas : 2 Vidas : 1 Nothing ghci runGameT test2 3 Inicio 3 Checkpoint anidado 3 Checkpoint anidado 2 Checkpoint anidado 1 Vida extra ! 2 Inicio 1 Finish Just ( Victoria ! ,1) -- John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.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
Re: [Haskell-cafe] Memoization in Haskell?
Thanks, okay the next question is: how does the memoization work? Each call to memo seems to construct a new array, if the same f(n) is encountered several times in the recursive branching, it would be computed several times. Am I wrong? Thanks, Mike Gregory Crosswhite wrote: On 7/8/10 9:17 PM, Michael Mossey wrote: Daniel Fischer wrote: If f has the appropriate type and the base case is f 0 = 0, module Memo where import Data.Array f :: (Integral a, Ord a, Ix a) = a - a f n = memo ! n where memo = array (0,n) $ (0,0) :[(i, max i (memo!(i `quot` 2) + memo!(i `quot` 3) + memo!(i `quot` 4))) | i - [1 .. n]] is wasteful regarding space, but it calculates only the needed values and very simple. Can someone explain to a beginner like me why this calculates only the needed values? The list comprehension draws from 1..n so I don't understand why all those values wouldn't be computed. The second pair of each element of the list will remain unevaluated until demanded --- it's the beauty of being a lazy language. :-) Put another way, although it might look like the list contains values (and technically it does due to referential transparency), at a lower level what it actually contains are pairs such that the second element is represented not by number but rather by a function that can be called to obtain its value. Cheers, Greg ___ 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] Memoization in Haskell?
You're correct in pointing out that f uses memoization inside of itself to cache the intermediate values that it commutes, but those values don't get shared between invocations of f; thus, if you call f with the same value of n several times then the memo table might get reconstructed redundantly. (However, there are other strategies for memoization that are persistent across calls.) Cheers, Greg On 7/8/10 9:59 PM, Michael Mossey wrote: Thanks, okay the next question is: how does the memoization work? Each call to memo seems to construct a new array, if the same f(n) is encountered several times in the recursive branching, it would be computed several times. Am I wrong? Thanks, Mike Gregory Crosswhite wrote: On 7/8/10 9:17 PM, Michael Mossey wrote: Daniel Fischer wrote: If f has the appropriate type and the base case is f 0 = 0, module Memo where import Data.Array f :: (Integral a, Ord a, Ix a) = a - a f n = memo ! n where memo = array (0,n) $ (0,0) :[(i, max i (memo!(i `quot` 2) + memo!(i `quot` 3) + memo!(i `quot` 4))) | i - [1 .. n]] is wasteful regarding space, but it calculates only the needed values and very simple. Can someone explain to a beginner like me why this calculates only the needed values? The list comprehension draws from 1..n so I don't understand why all those values wouldn't be computed. The second pair of each element of the list will remain unevaluated until demanded --- it's the beauty of being a lazy language. :-) Put another way, although it might look like the list contains values (and technically it does due to referential transparency), at a lower level what it actually contains are pairs such that the second element is represented not by number but rather by a function that can be called to obtain its value. Cheers, Greg ___ 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