Re: [Haskell-cafe] A model theory question
Alexander Solla wrote: > Doing similar constructions with type classes is possible. I think you > might have to use witness types (or even a nice functorial wrapper > around your target value in the original algebra, or both) to do > generalizations of type classes. For example: > > class Uneditable obj where > a :: a -> obj > b :: b -> obj > > class Refactored obj witness where > a' :: Maybe (a -> obj) > b' :: Maybe (a -> obj) > > data EmptyFilter -- I think the name of the extension needed for this is > 'EmptyDataDecls' > data NoA > data NoB > > instance Uneditable obj => Refactored obj EmptyFilter where a' = Just a; > b' = Just b > instance Uneditable obj => Refactored obj NoA where a' = Nothing; b' = > Just b Alexander, Thank you for your excellent explanation and example. Due to my lack of knowledge, I do not fully understand what is going in the example. I had a look at the types of a and a’. *Main> :t a a :: forall a obj. (Uneditable obj) => a -> obj *Main> :t a' a' :: forall witness a obj. (Refactored obj witness) => Maybe (a -> obj) Could you explain the example a little more. Apologies for my slowness. Pat This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web application framework comparison?
Hmm. Maybe we should sort this out. It's incomplete. The Web category is sporadic: http://www.haskell.org/haskellwiki/Category:Web Supposing we made a Web/Foo namespace and got some proper hierarchy. Of interest to most people are: * What can I do? * How can I do it? * Who has already done it? * Why did they do it like this? * What needs doing? * How up to date is all this information? Our discussions here, on IRC and on web-devel should really be documented. It should be that whenever we create or discover something substantial for web dev we should document it with examples on the Wiki. There isn't much centralised comparison of frameworks and libraries, either. One could make a table of frameworks/libraries and their features a la Wikipedia does. I don't know many frameworks but other people can fill the holes in. http://haskell.org/haskellwiki/Web is a good start, as is http://haskell.org/haskellwiki/Applications_and_libraries/Web_programming for examples http://www.haskell.org/haskellwiki/Formlets is also a good example of giving examples of a library. It's nice to link to some blog or external page but those disappear or lose relevance/compatibility over time, whereas a Wiki remains, and anyone can update it. For this reason I think it's a good idea for us to put work into the wiki. I'll reformat the entire Web category (immutably! I'll do it in Web/..) as a proposal, see what you guys think. Cheers On 27 September 2010 09:24, Jasper Van der Jeugt wrote: > Hey Dave, > > You should check out this page (if you haven't already): > http://haskell.org/haskellwiki/Web > > Cheers, > Jasper > > On Sun, Sep 26, 2010 at 8:41 PM, Dave Hinton wrote: >> There are 179 packages in the Web category on Hackage. >> >> It am finding it difficult, as someone who is not familiar with any of >> the Haskell web application frameworks on Hackage (and there seem to >> be at least 9), to determine which are good quality, which do things I >> would like a web framework to do for me, and which insist on doing >> things I would rather do myself. >> >> Is there a page comparing the major frameworks somewhere? I've been >> unable to find one via Google. >> ___ >> 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] Web application framework comparison?
On Tue, Sep 28, 2010 at 12:46 PM, Christopher Done wrote: > Hmm. Maybe we should sort this out. It's incomplete. The Web category > is sporadic: http://www.haskell.org/haskellwiki/Category:Web > > Supposing we made a Web/Foo namespace and got some proper hierarchy. > Of interest to most people are: > > * What can I do? > * How can I do it? > * Who has already done it? > * Why did they do it like this? > * What needs doing? > * How up to date is all this information? > > Our discussions here, on IRC and on web-devel should really be > documented. It should be that whenever we create or discover something > substantial for web dev we should document it with examples on the > Wiki. There isn't much centralised comparison of frameworks and > libraries, either. One could make a table of frameworks/libraries and > their features a la Wikipedia does. I don't know many frameworks but > other people can fill the holes in. > > http://haskell.org/haskellwiki/Web is a good start, as is > http://haskell.org/haskellwiki/Applications_and_libraries/Web_programming > for examples > > http://www.haskell.org/haskellwiki/Formlets is also a good example of > giving examples of a library. It's nice to link to some blog or > external page but those disappear or lose relevance/compatibility over > time, whereas a Wiki remains, and anyone can update it. For this > reason I think it's a good idea for us to put work into the wiki. > > I'll reformat the entire Web category (immutably! I'll do it in > Web/..) as a proposal, see what you guys think. +1. I did the rewrite of the /Web wiki page to try to make it more accessible. If you have a better format and want to move some of that content around, feel free to do so. Also, if you need any content or other assistance, please let me know. I think we need to improve our image on the wiki. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web application framework comparison?
On 28 September 2010 13:15, Michael Snoyman wrote: > +1. I did the rewrite of the /Web wiki page to try to make it more > accessible. If you have a better format and want to move some of that > content around, feel free to do so. Also, if you need any content or > other assistance, please let me know. Yeah, the /Web page is good stuff. The dates are especially a good idea! I want to flesh out the TODOs and re-shuffle some bits. I think the lists could be made into tables. The site's stylesheet doesn't really help. > I think we need to improve our image on the wiki. Agreed. Hopefully the new wiki will be rolled out soon. The current style sheet is "printable". It kinda makes every page look like a dead site. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web application framework comparison?
On Tue, Sep 28, 2010 at 2:03 PM, Christopher Done wrote: > On 28 September 2010 13:15, Michael Snoyman wrote: >> +1. I did the rewrite of the /Web wiki page to try to make it more >> accessible. If you have a better format and want to move some of that >> content around, feel free to do so. Also, if you need any content or >> other assistance, please let me know. > > Yeah, the /Web page is good stuff. The dates are especially a good > idea! I want to flesh out the TODOs and re-shuffle some bits. I think > the lists could be made into tables. The site's stylesheet doesn't > really help. I *do* really like having the dates there, but the problem is that someone has to actually update them. It would be nice if that could be automated, but I have a feeling that's asking for too much. >> I think we need to improve our image on the wiki. > > Agreed. Hopefully the new wiki will be rolled out soon. The current > style sheet is "printable". It kinda makes every page look like a dead > site. I wasn't aware there was a new wiki rolling out. Is there any more information available? Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web application framework comparison?
On 28 September 2010 14:06, Michael Snoyman wrote: > I *do* really like having the dates there, but the problem is that > someone has to actually update them. It would be nice if that could be > automated, but I have a feeling that's asking for too much. Probably too much. If the wiki made it trivial to embed feeds then it would be easy. As long as the documentation and examples has a version number attached to it, I think that's most important. Is this documentation recent or two main versions ago? I don't mind out of date documentation if it's explicitly labelled, then I can choose to garner information from it or ignore it and not waste my time. > I wasn't aware there was a new wiki rolling out. Is there any more > information available? Thomas Schilling (aka. nomilo) is working on it: http://www.haskell.org/pipermail/haskell/2010-September/022309.html http://new-www.haskell.org/haskellwiki/Haskell ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web application framework comparison?
On Tue, Sep 28, 2010 at 2:33 PM, Christopher Done wrote: > On 28 September 2010 14:06, Michael Snoyman wrote: >> I *do* really like having the dates there, but the problem is that >> someone has to actually update them. It would be nice if that could be >> automated, but I have a feeling that's asking for too much. > > Probably too much. If the wiki made it trivial to embed feeds then it > would be easy. As long as the documentation and examples has a version > number attached to it, I think that's most important. Is this > documentation recent or two main versions ago? I don't mind out of > date documentation if it's explicitly labelled, then I can choose to > garner information from it or ignore it and not waste my time. > >> I wasn't aware there was a new wiki rolling out. Is there any more >> information available? > > Thomas Schilling (aka. nomilo) is working on it: > > http://www.haskell.org/pipermail/haskell/2010-September/022309.html > > http://new-www.haskell.org/haskellwiki/Haskell > Looks good, the /Web page looks much nicer over there: http://new-www.haskell.org/haskellwiki/Web Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question on monad transformers stack
Arnaud, You might also consider writing monad-agnostic code: code that doesn't know which monad it is executing in. For example: >class (Monad g) => MonadGit g where > gitOp1 :: > gitOp2 :: > > >instance MonadGit Git where > gitOp1 = ... > gitOp2 = ... > ... > >intance MonadGit DebugGit where > gitOp1 = ... > gitOp2 = ... > >otherGitOp :: (MonadGit g) => a -> b -> g a >otherGitOp = gitOp1 . gitOp2 . otherF . etc In other words, you create a typeclass that (at least) two different monads will implement. One which runs the code normally, while the other performs the debug actions that you described. Then your "debug flag" becomes a choice of which monad to begin execution in. Note that this can be a bit cumbersome (but I don't think impossible) if the debug flag has to be changed at runtime. Hope this helps, --Jonathan On Tue, Sep 28, 2010 at 12:56 AM, Arnaud Bailly wrote: > Hello Cafe, > > I have the following type which represents some action using Git > >> newtype (Monad m) => Git m a = Git { runGit :: ErrorT String (StateT >> Environment m) a } >> deriving (Monad, MonadState Environment, MonadError String) > > and the following typeclass whose purpose is to abstract away the > details of executing commands in the OS, with an obvious IO instance, > and to ease testing of commands effects: > >> -- | A monad for simple execution of a process within the >> class (MonadError e m) => MonadExec e m where >> debug :: String -> m () >> exec :: String -> [String] -> m String >> -- ^Do not really execute commande but output the command string and >> arguments passed >> exec' :: String -> [String] -> m String >> exec' proc args = return $ program proc args > > The type environment is : > >> data Environment = Env { debugMode :: Bool, >> baseDirectory :: FilePath, >> maven :: FilePath, >> git :: FilePath, >> p4 :: FilePath, >> javaHome :: FilePath} >> deriving (Eq, Show, Read) > > This follows the monad stack pattern presented in RWH and in Don > Stewart's presentation on scripting with haskell. Actually, what I am > trying to achieve is to be able to write my own scripts in Haskell. > > What I would like to do is to be able to wrap each Git action occuring > in a MonadExec instance into a call to debug according to the status > of the debugMode flag in environment, in order to prevent the need of > explicit calls to debug. Something like the -v flag in bash... > > I can imagine being able to do this using 2 different ways: > - add a constraint on Git monad and write explicitly return and >>= > to use debug > - push the environment or part of it inside the MonadExec, for > example as a Reader. > > What is the "best" (i.e. most economical) way of doing this? > > Thanks for your advices. > > Arnaud Bailly > ___ > 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] Non-strict evaluation and concurrency (STM) : conflict?
Hi, I'm working on Concurrent Haskell, especially with the monad STM. I don't fully understand the way my program is executed. I think the lazy evaluation leads to a loss of performance, if we don't pay attention to this problem. A short example will be more explicit : Imagine this scenario : we have a set of threads (the workers) that have (each) a result to compute (purely). When finished, they try to save the result in an shared inbox, using STM. If the inbox is full, the thread waits until the inbox is empty. A specific thread is looking at the inbox: when it finds a value in the inbox, it prints the value on the screen (for example, it could be any processing based on the value) and then empty the inbox and wait that a remaining thread add a new value). Let's a function "do_job", the function to execute by the threads (the workers) : do_job :: (b -> a) -> b -> Inbox a -> IO () do_job f input inbox = do { value <- return (f input) ; atomically ( writeMsg inbox value ) } The idea is : (f input) is the function to compute. Once compute, we want to save the result atomically. The problem is, because of the lazy evaluation, the "value" is computed in the atomic section, and not before, resulting in a loss of efficiency. Indeed, to be fast, a concurrent program has to keep the atomic sections as "small" as possible, because it limits the parallelism. To illustrate this, let's see this source code : module Main where import Control.Concurrent import Control.Concurrent.STM import Data.Maybe import System.Random import System.IO {-- Inbox --} type Inbox a = TVar (Maybe a) createInbox :: STM (Inbox a) createInbox = newTVar Nothing readMsg :: Inbox a -> STM a readMsg inbox = do { inboxContent <- readTVar inbox ; if (isNothing inboxContent) then retry else do { writeTVar inbox Nothing ; return (fromJust inboxContent) } } writeMsg :: Inbox a -> a -> STM () writeMsg inbox value = do { inboxContent <- readTVar inbox ; if (isNothing inboxContent) then writeTVar inbox (Just value) else retry } {-- Workers --} * do_job :: (b -> a) -> b -> Inbox a -> IO ()* *do_job f input inbox = do { value <- return (f input) * * ; atomically ( writeMsg inbox value ) }* do_jobs_in_threads :: [((b->a),b)] -> Inbox a -> TVar Int -> IO () do_jobs_in_threads [] _ _ = return () do_jobs_in_threads ((f,input):xs) inbox flag = do { forkIO_and_notify flag (do_job f input inbox) ; do_jobs_in_threads xs inbox flag } {-- Caller --} * * *caller :: Inbox a -> (a -> IO ()) -> Int -> IO ()* *caller _ _ 0 = return ()* *caller inbox process n = do { msg <- atomically (readMsg inbox)* *; process msg * *; caller inbox process (n-1) }* caller_in_thread flag inbox process n = forkIO_and_notify flag (caller inbox process n) {-- forkIO with notification --} create_flag = atomically ( newTVar 0 ) forkIO_and_notify :: TVar Int -> IO () -> IO () forkIO_and_notify tvar action = do { atomically ( do { oldValue <- readTVar tvar ; writeTVar tvar (oldValue + 1) } ) ; forkIO (do { action ; atomically ( do { oldValue <- readTVar tvar ; writeTVar tvar (oldValue - 1) } ) } ) --; putStrLn "Tread lancé" } ; return () } waitFlag flag = atomically ( do { valueflag <- readTVar flag ; if valueflag > 0 then retry else return () } ) {-- main --} main :: IO () main = do { flag <- create_flag ; inbox <- atomically (createInbox) ; *caller_in_thread flag inbox (\x -> putStrLn ("Caller : "++ (show (x 3* * ; do_jobs_in_threads [(perm,[1..11]),(perm,[1..8]),(perm,[1..3])] inbox flag* ; waitFlag flag ; return () } where perm (l:ls) = injectett l (perm ls) injectett x (l:ls) = injecte x l ++ injectett x ls injecte x (l:ls) = [x:l:ls]++map (l:) (injecte x ls) inputs = zip (replicate 3 f) [[1..11],[1..8],[1..3]] As you can see, we ask for 3 threads to compute permutations for [1..11], [1..8] and [1..3]. The "Caller" write a message when a thread finished. What we expect is that the second and third thread finish their work before the first one. But the output of this program is : *Caller : 39916800* *Caller : 40320* *Caller : 6* ... which means that threads 2 and 3 have to wait the first thread before being able to save (and probably compute) their own result. If I force to evaluate "value" before the atomic section, by defining : do_job :: (b -> a) -> b -> Inbox a -> IO () do_job f input inbox = do { value <- return (f input) ; value `seq` atomically ( writeMsg inbox value ) } Then I obtain a more efficient program, as the output
Re: [Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?
Excerpts from Romain Demeyer's message of Tue Sep 28 09:06:53 -0400 2010: > That's what we want, but what is the explanation of this behavior? STM is > designed to be optimistic, not blocking. So, does it means that the "value" > is evaluated at "commit-time"? > Do you know some problems that are related or do you know some works that > can be useful at this subject? STM's interface is lazy; so you have to tell Haskell when to evaluate computationally expensive thunks, otherwise it will wait till the last possible moment. This is a common trip up point for concurrency programming. Don Stewart wrote strict-concurrency, which is a strict version of MVars and Chans, though I don't see a strict STM class. Edward ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question on monad transformers stack
Look rather obvious when explained :-) And this is a pattern I have already used for other code :-( Thanks a lot Jonathan, that's indeed quite helpful. Regards Arnaud On Tue, Sep 28, 2010 at 3:03 PM, Jonathan Geddes wrote: > Arnaud, > > You might also consider writing monad-agnostic code: code that doesn't > know which monad it is executing in. > > For example: > >>class (Monad g) => MonadGit g where >> gitOp1 :: >> gitOp2 :: >> >> >>instance MonadGit Git where >> gitOp1 = ... >> gitOp2 = ... >> ... >> >>intance MonadGit DebugGit where >> gitOp1 = ... >> gitOp2 = ... >> >>otherGitOp :: (MonadGit g) => a -> b -> g a >>otherGitOp = gitOp1 . gitOp2 . otherF . etc > > In other words, you create a typeclass that (at least) two different > monads will implement. One which runs the code normally, while the > other performs the debug actions that you described. Then your "debug > flag" becomes a choice of which monad to begin execution in. Note that > this can be a bit cumbersome (but I don't think impossible) if the > debug flag has to be changed at runtime. > > Hope this helps, > > --Jonathan > > > On Tue, Sep 28, 2010 at 12:56 AM, Arnaud Bailly > wrote: >> Hello Cafe, >> >> I have the following type which represents some action using Git >> >>> newtype (Monad m) => Git m a = Git { runGit :: ErrorT String (StateT >>> Environment m) a } >>> deriving (Monad, MonadState Environment, MonadError String) >> >> and the following typeclass whose purpose is to abstract away the >> details of executing commands in the OS, with an obvious IO instance, >> and to ease testing of commands effects: >> >>> -- | A monad for simple execution of a process within the >>> class (MonadError e m) => MonadExec e m where >>> debug :: String -> m () >>> exec :: String -> [String] -> m String >>> -- ^Do not really execute commande but output the command string and >>> arguments passed >>> exec' :: String -> [String] -> m String >>> exec' proc args = return $ program proc args >> >> The type environment is : >> >>> data Environment = Env { debugMode :: Bool, >>> baseDirectory :: FilePath, >>> maven :: FilePath, >>> git :: FilePath, >>> p4 :: FilePath, >>> javaHome :: FilePath} >>> deriving (Eq, Show, Read) >> >> This follows the monad stack pattern presented in RWH and in Don >> Stewart's presentation on scripting with haskell. Actually, what I am >> trying to achieve is to be able to write my own scripts in Haskell. >> >> What I would like to do is to be able to wrap each Git action occuring >> in a MonadExec instance into a call to debug according to the status >> of the debugMode flag in environment, in order to prevent the need of >> explicit calls to debug. Something like the -v flag in bash... >> >> I can imagine being able to do this using 2 different ways: >> - add a constraint on Git monad and write explicitly return and >>= >> to use debug >> - push the environment or part of it inside the MonadExec, for >> example as a Reader. >> >> What is the "best" (i.e. most economical) way of doing this? >> >> Thanks for your advices. >> >> Arnaud Bailly >> ___ >> 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] Non-strict evaluation and concurrency (STM) : conflict?
On Tue, Sep 28, 2010 at 10:06 AM, Romain Demeyer wrote: > Let's a function "do_job", the function to execute by the threads (the > workers) : > do_job :: (b -> a) -> b -> Inbox a -> IO () > do_job f input inbox = do { value <- return (f input) > ; atomically ( writeMsg inbox value ) } First of all, note that do v <- return (f x) ... is exactly the same as do let v = f x ... Now, if you want to evaluate your value to WHNF (Weak Head Normal Formal), you may use > do_job :: (b -> a) -> b -> Inbox a -> IO () > do_job f input inbox = do > value <- evaluate (f input) > atomically (writeMsg inbox value) This will work pretty well if your value is simple (eg. an Int) but not so well if it is complex (eg. a Data.Map) because it will evaluate only as much as 'seq'. You may than use the 'deepseq' package: > import Control.DeepSeq > > do_job :: NFData a => (b -> a) -> b -> Inbox a -> IO () > do_job f input inbox = > let value = f input > in value `deepseq` atomically (writeMsg inbox value) This will fully evaluate the structure before calling 'writeMsg'. > That's what we want, but what is the explanation of this behavior? STM is > designed to be optimistic, not blocking. So, does it means that the "value" > is evaluated at "commit-time"? > Do you know some problems that are related or do you know some works that > can be useful at this subject? Those values are pure, so if you say writeMsg inbox (f x) then internally a thunk is created referencing 'f' and 'x', and a pointer to that thunk is atomically commited. Just like the rest of the program. The value is not being evaluated by STM at all, as your STM functions don't need the value. In your program is evaluating when you print the answer in the main thread, as printing requires the value of the computation. If you didn't print, nothing would be computed at all. Lazy =). HTH, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Relaxing atomicity of STM transactions
Has anyone in the STM community considered the ability to read a TVar, such that it would allow the transaction to complete even if the TVar was modified by another transaction? (I am assuming this is not how STM works by default.) For example: looselyReadTVar :: TVar a -> STM a Atom [1] has similar semantics to STM. If Atom were to relax it's rule atomicity in this fashion, it could open the door to improved task scheduling and higher levels of program description. Has STM research already gone down this path? -Tom [1] http://hackage.haskell.org/package/atom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
On 28 September 2010 15:35, Tom Hawkins wrote: > Has anyone in the STM community considered the ability to read a TVar, > such that it would allow the transaction to complete even if the TVar > was modified by another transaction? Maybe something like this: (Pasted from http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/GHC-Conc.html#v%3AreadTVarIO ) readTVarIO :: TVar a -> IO a Return the current value stored in a TVar. This is equivalent to readTVarIO = atomically . readTVar but works much faster, because it doesn't perform a complete transaction, it just reads the current value of the TVar. Peter > (I am assuming this is not how > STM works by default.) For example: > > looselyReadTVar :: TVar a -> STM a > > Atom [1] has similar semantics to STM. If Atom were to relax it's > rule atomicity in this fashion, it could open the door to improved > task scheduling and higher levels of program description. Has STM > research already gone down this path? > > -Tom > > [1] http://hackage.haskell.org/package/atom > ___ > 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] Relaxing atomicity of STM transactions
Hi Tom, you can do this with Twilight STM. I recently uploaded the first version on hackage[1]. The next version including a better algorithm and examples is about to be released in a few days. Twilight STM features include tagging of variables and fine-grained conflict detection, flexible isolation level semantics (snapshot isolation and opacity) as well as safe integration of I/O. - Annette [1] http://hackage.haskell.org/package/twilight-stm Am 28.09.2010 15:35, schrieb Tom Hawkins: > Has anyone in the STM community considered the ability to read a TVar, > such that it would allow the transaction to complete even if the TVar > was modified by another transaction? (I am assuming this is not how > STM works by default.) For example: > > looselyReadTVar :: TVar a -> STM a > > Atom [1] has similar semantics to STM. If Atom were to relax it's > rule atomicity in this fashion, it could open the door to improved > task scheduling and higher levels of program description. Has STM > research already gone down this path? > > -Tom > > [1] http://hackage.haskell.org/package/atom > ___ > 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] Relaxing atomicity of STM transactions
On Tue, Sep 28, 2010 at 10:41 AM, Peter Robinson wrote: > readTVarIO :: TVar a -> IO a One needs to know if it is ok to wrap this IO action into an STM action. For example, > data I a = I a > > looselyReadTVar :: TVar a -> STM a > looselyReadTVar tvar = > let v = unsafePerformIO (I <$> readTVarIO tvar) > in case v of I x -> return x The 'case' is needed because otherwise the TVar would be read only when its value was requested, and we want to keep the ordering. The 'I' datatype is used to avoid evaluating the user's value (which could even be 'undefined'). Note that this function can be used on any monad, but I don't think that is a good idea =). Cheers! -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
On Tue, Sep 28, 2010 at 8:54 AM, Felipe Lessa wrote: > On Tue, Sep 28, 2010 at 10:41 AM, Peter Robinson wrote: >> readTVarIO :: TVar a -> IO a > > One needs to know if it is ok to wrap this IO action into an STM > action. For example, > >> data I a = I a >> >> looselyReadTVar :: TVar a -> STM a >> looselyReadTVar tvar = >> let v = unsafePerformIO (I <$> readTVarIO tvar) >> in case v of I x -> return x > > The 'case' is needed because otherwise the TVar would be read > only when its value was requested, and we want to keep the > ordering. The 'I' datatype is used to avoid evaluating the > user's value (which could even be 'undefined'). > > Note that this function can be used on any monad, but I don't > think that is a good idea =). > > Cheers! > Isn't there an 'unsafeIOToSTM' function somewhere? Something like: > unsafeIOToSTM (IO k) = STM k Then you might not need the case statement. Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
On Tue, Sep 28, 2010 at 11:01 AM, Antoine Latter wrote: > Isn't there an 'unsafeIOToSTM' function somewhere? Something like: > >> unsafeIOToSTM (IO k) = STM k > > Then you might not need the case statement. I thought there was, but I couldn't find it in the 'stm' package [1], using Hoogle [2] nor using Hayoo [3]. [1] http://hackage.haskell.org/package/stm [2] http://haskell.org/hoogle/?hoogle=IO+a+-%3E+STM+a [3] http://holumbus.fh-wedel.de/hayoo/hayoo.html#0:stmtoio -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
On Tue, Sep 28, 2010 at 9:05 AM, Felipe Lessa wrote: > On Tue, Sep 28, 2010 at 11:01 AM, Antoine Latter wrote: >> Isn't there an 'unsafeIOToSTM' function somewhere? Something like: >> >>> unsafeIOToSTM (IO k) = STM k >> >> Then you might not need the case statement. > > I thought there was, but I couldn't find it in the 'stm' package [1], > using Hoogle [2] nor using Hayoo [3]. > Funny - I had the module open in another window as I wrote my response. It's in GHC.Conc[1]: > unsafeIOToSTM :: IO a -> STM a defined as I had guessed. Antoine [1] http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/GHC-Conc.html#v%3AunsafeIOToSTM ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?
Thanks for your help. It's more clear now. > The value is not being evaluated by STM at all, as your STM functions > don't need the value. In your program is evaluating when you print > the answer in the main thread, as printing requires the value of the > computation. If you didn't print, nothing would be computed at all. > Lazy =). Does it means that the value is computed *by* the "caller", based on the thunk, and not by the worker itself? In this case, in this specific example, it would mean that this program does not exploit the parallelism at all (except using deepseq or seq). I understand the principles (lazy evaluation, thunk,...) , but I'm surprised that no work has been done to "solve" this problem (in the sense that it's not intuitive to write concurrent programs in this context). ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Non-strict evaluation and concurrency (STM) : conflict?
On Tue, Sep 28, 2010 at 11:38 AM, Romain Demeyer wrote: > Does it means that the value is computed by the "caller", based on the > thunk, and not by the worker itself? It is computed by the one who needs the value. Your worker doesn't. Note that the value is computed on 'print', which is *after* the worker has returned the value. So, it is the caller who evaluates, but it does not evaluate while calling the worker. > In this case, in this specific example, it would mean that this program does > not exploit the parallelism at all (except using deepseq or seq). > I understand the principles (lazy evaluation, thunk,...) , but I'm surprised > that no work has been done to "solve" this problem (in the sense that it's > not intuitive to write concurrent programs in this context). It is not a problem, it is a feature. It is our beloved lazy evaluation applied to STM. Alas, there isn't a single "solution". You may want 'seq', 'deepseq' or something between. Your data may already be in WHNF or HNF, so calling 'seq' or 'deepseq' always would decrease performance for no gain on these cases. And sometimes you really want the lazy behaviour, for example, if you were using an infinite data structure. It is only a problem when you are learning how to use concurrency or parallelism in Haskell. Just repeat to yourself that everything is lazy and you'll get used to it =). Cheers, -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Inverse of HaskellDB
Hey Jonathan, I've done some work on this. The hard part is defining relationships between datatypes: how do you model this in Haskell? I've some code on github: http://github.com/chriseidhof/persist, you might be interested in that. -chris On 25 sep 2010, at 21:31, Jonathan Geddes wrote: > Cafe, > > HaskellDB takes a database schema and produces Haskell data structures > (plus some other query-related stuff for its EDSL query language). > > What I'm looking for is the inverse of this functionality. I want to > create tables based on a Haskell data structure with a few simple > rules. These rules include: if a field is not of the form `Maybe a' > then it can't be nullable in the database. If a field is not a > primitive (in the database) then it is actually stored in another > table and a reference id is stored in the table. Tables are produced > recursively, unless they already exist, etc. > > The HaskellDB approach is great for interfacing with existing tables, > but in my case I already have data structures and now I would like a > quick way to create tables to persist them. > > Does such a thing exist? If not, would you find it useful? I may take > this up as a side project if it does not already exist and others > would find it useful. > > Thanks, > > --Jonathan > ___ > 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] Inverse of HaskellDB
Do you need to persistently store your Haskell data types in tables ? Or just persistently store them ? happstack-state provides the latter for you. Your data-types are just plain-old Haskell data types and your queries and updates are just functions in the Reader or State monad. It provides ACID properties with write-ahead logging to the disk, S3, or other backends. It also includes data-type versioning and automatic migration. Although it is associated with the happstack web application framework, there is nothing web specific about it. It does not even require that you build or install any of the web stuff in Happstack. To get a quick feel for how it works, I recommend this tutorial: http://nhlab.blogspot.com/2008/07/extending-asterisk-with-happs.html It is a little out of date -- but mostly you just need to change the imports from HAppS to Happstack. - jeremy On Sat, Sep 25, 2010 at 2:31 PM, Jonathan Geddes wrote: > Cafe, > > HaskellDB takes a database schema and produces Haskell data structures > (plus some other query-related stuff for its EDSL query language). > > What I'm looking for is the inverse of this functionality. I want to > create tables based on a Haskell data structure with a few simple > rules. These rules include: if a field is not of the form `Maybe a' > then it can't be nullable in the database. If a field is not a > primitive (in the database) then it is actually stored in another > table and a reference id is stored in the table. Tables are produced > recursively, unless they already exist, etc. > > The HaskellDB approach is great for interfacing with existing tables, > but in my case I already have data structures and now I would like a > quick way to create tables to persist them. > > Does such a thing exist? If not, would you find it useful? I may take > this up as a side project if it does not already exist and others > would find it useful. > > Thanks, > > --Jonathan > ___ > 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] Inverse of HaskellDB
> > How do you define relationships between data types? Well, why is it any different from other fields? From one of your examples [1], I'd expect you to have a list of questions in the Quiz data type, and if necessary, a quiz field in the Question data type. This might be a bit tricky but certainly achievable [2]. Something like the following: data Quiz = Quiz { description :: String, subject :: String, questions :: [Question] } deriving (Show, Read) data Question = Question { title :: String, choiceA :: String, choiceB :: String, choiceC :: String, quiz:: Quiz } deriving (Show, Read) [1] http://github.com/chriseidhof/persist/blob/master/examples/Model.phs [2] http://www.haskell.org/haskellwiki/Tying_the_Knot On 28 September 2010 16:13, Chris Eidhof wrote: > Hey Jonathan, > > I've done some work on this. The hard part is defining relationships > between datatypes: how do you model this in Haskell? I've some code on > github: http://github.com/chriseidhof/persist, you might be interested in > that. > > -chris > > On 25 sep 2010, at 21:31, Jonathan Geddes wrote: > > > Cafe, > > > > HaskellDB takes a database schema and produces Haskell data structures > > (plus some other query-related stuff for its EDSL query language). > > > > What I'm looking for is the inverse of this functionality. I want to > > create tables based on a Haskell data structure with a few simple > > rules. These rules include: if a field is not of the form `Maybe a' > > then it can't be nullable in the database. If a field is not a > > primitive (in the database) then it is actually stored in another > > table and a reference id is stored in the table. Tables are produced > > recursively, unless they already exist, etc. > > > > The HaskellDB approach is great for interfacing with existing tables, > > but in my case I already have data structures and now I would like a > > quick way to create tables to persist them. > > > > Does such a thing exist? If not, would you find it useful? I may take > > this up as a side project if it does not already exist and others > > would find it useful. > > > > Thanks, > > > > --Jonathan > > ___ > > 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 > -- Ozgur Akgun ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] HackageDB: Haddock parse failure
Den 27 september 2010 18:22 skrev Jonas Almström Duregård : > HackageDB reports a build failure for happy-meta-0.1.1 > (http://hackage.haskell.org/package/happy-meta-0.1.1), but from the > log it seems that the failure occurs when building the documentation. > > The error is > src/LALR.lhs:230:2: parse error on input `numberSets' > > I'm guessing there is no syntax error in this file (it is taken from > Happy), but rather an error in Haddock? I suspect this has something to do with the comment before that line. I might be wrong but I think Cabal turns the text in literal haskell files into haddock comments. If that's the case then you have to be careful to not use haddock comment markup in the wrong way. David ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Web application framework comparison?
On Tue, Sep 28, 2010 at 5:46 AM, Christopher Done wrote: > http://haskell.org/haskellwiki/Applications_and_libraries/Web_programming > for examples If you search on google for 'haskell web framework' that link actually comes up higher than any other wiki page.. and it does seem to have more complete entries in many ways.. Not sure what that means. But I am only willing to maintain so many wiki pages. So far at least three have come up in this thread. - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??
Avoiding repeated additions: movingAverage :: Int -> [Float] -> [Float] movingAverage n l = runSums (sum . take n $l) l (drop n l) where n' = fromIntegral n runSums sum (h:hs) (t:ts) = sum / n' : runSums (sum-h+t) hs ts runSums _ _ [] = [] Doaitse On 28 sep 2010, at 03:40, Richard O'Keefe wrote: > > On 27/09/2010, at 5:20 AM, rgowka1 wrote: > >> Type signature would be Int -> [Double] -> [(Double,Double)] >> >> Any thoughts or ideas on how to calculate a n-element moving average >> of a list of Doubles? >> >> Let's say [1..10]::[Double] >> >> what is the function to calculate the average of the 3 elements? >> >> [(1,0),(2,0),(3,2),(4,3)] :: [(Double,Double)] > >> moving_average3 (xs0 @ (_ : (xs1 @ (_ : xs2 = >> zipWith3 (\x y z -> (x+y+z)/3) xs0 xs1 xs2 > > *Main> moving_average3 [1..10] > [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0] > > The result is two elements shorter than the original, but that > _is_ the definition of moving average after all. > ___ > 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: Non-strict evaluation and concurrency (STM) : conflict?
Romain Demeyer wrote: > Imagine this scenario : we have a set of threads (the workers) that have > (each) a result to compute (purely). When finished, they try to save the > result in an shared inbox, using STM. If the inbox is full, the thread > waits until the inbox is empty. > A specific thread is looking at the inbox: when it finds a value in the > inbox, it prints the value on the screen (for example, it could be any > processing based on the value) and then empty the inbox and wait that a > remaining thread add a new value). The technical reason this does not work as expected was given by others (lazy evaluation, etc). One additional remark: It seems you are using STM for parallelism, i.e. to enhance performance, not for explicit concurrency. (Otherwise it would make no difference to you which thread actually evaluates some expression). This can be done much easier with the `par` combinator and friends (http://hackage.haskell.org/package/parallel). The same caveat wrt lazyness applies to this method, but your code will become a lot simpler: no need to explicitly manage threads, pure functional (non-monadic) code. Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
Thanks for the responses, but I think I should explain a bit more. I'm not interested in being able to read the live value of a TVar at any arbitrary time (via. unsafeIOToSTM). But rather I would like looslyReadTVar to have exactly the same semantics as readTVar, except that the STM runtime would not reject the transaction if the TVar is modified by another transaction before the atomic commit takes place. Also, as I would be implementing something similar in Atom, I'm not necessarily interested in a Haskell implementation, but rather if the programming experience is elevated by these alternative semantics. For example: incr :: TVar -> STM () incr a = looslyReadTVar a >>= writeTVar a . (+ 1) decr a :: TVar -> STM () decr a = readTVar a >>= writeTVar a . (- 1) If incr and decr where atomically started at the same time with the same TVar, decr would be rejected if incr completed first, but not the other way around. The initial reaction may be that this seriously breaks the atomicity of STM, but there may be cases where this could be useful. For instance, it allow a computationally expensive transactions to complete, even if their inputs are constantly being modified. In the embedded domain, this could be a fault monitor that reads a bunch of constantly changing sensors. -Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
2010/9/29 Tom Hawkins : > In the embedded domain, this could be a fault monitor that > reads a bunch of constantly changing sensors. I think that sensor reading belongs to IO, not STM. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ICFP2010 contest results?
I saw the winner was announced. Is there a highscore table? We were in the top 5, I want to see how well we did. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
On Tue, Sep 28, 2010 at 6:44 PM, Serguey Zefirov wrote: > 2010/9/29 Tom Hawkins : >> In the embedded domain, this could be a fault monitor that >> reads a bunch of constantly changing sensors. > > I think that sensor reading belongs to IO, not STM. > Sensors would be transfered from IO to TVars via a transaction in an input processing thread. My question is not this, but is looselyReadTVar advantageous to STM programming in general? My applications can't use Haskell STM, nor the Haskell runtime, due to their hard realtime requirements. -Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Retargeting Haskell compiler to embedded/hardware
A few years ago I attempted to build a Haskell hardware compiler (Haskell -> Verilog) based on the Yhc frontent. At the time I was trying to overcome several problems [1] with implementing a hardware description language as a light eDSL, which convinced me a proper compiler may be a better approach. Yhc was recommended as a good starting point since it had a simpler IR compared with GHC -- at least at the time. I am considering restarting this effort, but this time to target hard realtime embedded code. What is the recommended compiler to start from? I need an IR that is post type checking with as much desugaring as possible, and a code base that is relatively easy to splice and build. My other requirement is not to be bound to IO () for 'main'. The top level will be a monad, but with different semantics than IO. I would also like to reuse the standard library, with exception to the values related to IO. What are my options? Thanks. -Tom [1] Lack of observable sharing; function definitions, case expressions, ADTs disappear at compile time; etc. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
On Sep 28, 2010, at 6:36 PM, Tom Hawkins wrote: Thanks for the responses, but I think I should explain a bit more. I'm not interested in being able to read the live value of a TVar at any arbitrary time (via. unsafeIOToSTM). But rather I would like looslyReadTVar to have exactly the same semantics as readTVar, except that the STM runtime would not reject the transaction if the TVar is modified by another transaction before the atomic commit takes place. Given the current implementation, I think the easiest way to get those semantics is to lift the untracked readTVarIO into STM with unsafeIOToSTM. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Retargeting Haskell compiler to embedded/hardware
Hi, --- On Wed, Sep 29, 2010 at 7:28 AM, Tom Hawkins wrote: | A few years ago I attempted to build a Haskell hardware compiler | (Haskell -> Verilog) based on the Yhc frontent. \-- If you are still at it, you can have a look at Chalmers Lava [1], or Kansas Lava [2]. --- | I am considering restarting this effort, but this time to target hard | realtime embedded code. \-- Feldspar [3] project targets DSP though. SK [1] Chalmers Lava. http://hackage.haskell.org/package/chalmers-lava2000 [2] Kansas Lava. http://www.ittc.ku.edu/csdl/fpg/Tools/KansasLava [3] Feldspar. http://feldspar.inf.elte.hu/feldspar/ -- Shakthi Kannan http://www.shakthimaan.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Coding conventions for Haskell?
On Tue, Sep 28, 2010 at 5:55 AM, Evan Laforge wrote: > > I write haskell and python in a proportional font and it hasn't yet > let to tabs, so no pain so far :) > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > I like writing proportional haskell, but I haven't worked out how to do let-blocks in ways that look nice - the tactic I use for do and where of breaking the line immediately tends to look a little odd, especially if you're only making about one binding. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Retargeting Haskell compiler to embedded/hardware
On Tue, Sep 28, 2010 at 9:20 PM, Shakthi Kannan wrote: > If you are still at it, you can have a look at Chalmers Lava [1], or > Kansas Lava [2]. > Feldspar [3] project targets DSP though. These are examples light embedded DSLs, i.e. sophisticated libraries where you compile, then run the program to generate code. This is not what I want. Rather, I am looking for advice on how to splice GHC -- or another implementation -- where I can build a compiler starting from a type checked, simplified Haskell AST; or better yet, an unevaluated call graph. -Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
On Tue, Sep 28, 2010 at 9:19 PM, Brandon Moore wrote: > > > On Sep 28, 2010, at 6:36 PM, Tom Hawkins wrote: > > Thanks for the responses, but I think I should explain a bit more. > I'm not interested in being able to read the live value of a TVar at > any arbitrary time (via. unsafeIOToSTM). But rather I would like > looslyReadTVar to have exactly the same semantics as readTVar, except > that the STM runtime would not reject the transaction if the TVar is > modified by another transaction before the atomic commit takes place. > > Given the current implementation, I think the easiest way to get those > semantics is to lift the untracked readTVarIO into STM with unsafeIOToSTM. > Even though I thought it was awsome up above, it is a really unsafe function with that implementation: --- import GHC.Conc import Control.Monad readTVarLoose :: TVar a -> STM a readTVarLoose = unsafeIOToSTM . readTVarIO testAction tv = do readTVar tv >>= writeTVar tv . succ (,) `fmap` readTVar tv `ap` readTVarLoose tv main = do tv <- newTVarIO 3 (a,b) <- atomically $ testAction tv print a print b --- What's happening is that readTVarIO doesn't know to hit the transaction log for the "true" value of the TVar. So we need something that will read previous entries in the transaction log, but will not write to the transaction log. You'll need a new primop for this, which would be implemented in rts/STM.c It looks like you would take most of stmReadTVar from STM.c, and get rid of everything that calls get_new_entry. Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Parsec question (new user): unexpected end of input
I am a new Parsec user, and having some trouble with a relatively simple parser. The grammar I want to parse contains tags (not html) marked by angle brackets (e.g., ""), with arbitrary text (no angle brackets allowed) optionally in between tags. Tags may not nest, but the input must begin and end with a tag. Whitespace may occur anywhere (beginning/end of input, inside/between tags, etc.), and is optional. I think my problem may be a lack of using "try", but I'm not sure where. At runtime I get: Error parsing file: "...\sampleTaggedContent.txt" (line 4, column 1): unexpected end of input expecting "<" The input was: stuff more stuff < tag 3 > even more The code is below. (I'm using Parsec-2.1.0.1.) I don't really want to return anything meaningful yet; just parse okay. Any advice about the error (or how to simplify or improve the code) would be appreciated. Thanks much, -- Peter > -- Parsers: > taggedContent = do >optionalWhiteSpace >aTag >many tagOrContent >aTag >eof >return "Parse complete." > > tagOrContent = aTag <|> someContent "tagOrContent" > > aTag = do >tagBegin >xs <- many (noneOf [tagEndChar]) >tagEnd >optionalWhiteSpace >return () > > someContent = do >manyTill anyChar tagBegin >return () > > optionalWhiteSpace = spaces -- i.e., any of " \v\f\t\r\n" > tagBegin = char tagBeginChar > tagEnd = char tagEndChar > > -- Etc: > tagBeginChar = '<' > tagEndChar = '>' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A model theory question
On 09/28/2010 03:03 AM, Patrick Browne wrote: I had a look at the types of a and a’. *Main> :t a a :: forall a obj. (Uneditable obj) => a -> obj *Main> :t a' a' :: forall witness a obj. (Refactored obj witness) => Maybe (a -> obj) Could you explain the example a little more. This is going to be a long email. Logic is a bit of a rambling subject. And then I went out and bought some beer. ;0) First thing to note: the importance of the types here is that the stuff contained inside the Maybe HAS to be the same type as the corresponding "Uneditable" function. On a conceptual level, we're trying to quantify over the axioms embodied by "Uneditable". It isn't important to my point what the axioms types are. What matters is that the new axiom scheme as the same "inner" type, wrapped in a Maybe. If you're looking to do object orientation or similar things, you would probably prefer something like: class Uneditable obj where a :: obj -> a; b :: obj -> a and class Refactored obj witness where a' :: Maybe (obj -> a), b' :: Maybe (obj -> a) You can do slick things with existential quantification too. (To a mathematician, "slick" means "so elegant it looks trivial at first glance, but deep and unifying upon further inspection". Compare to the mathematician joke about obviousness.[1] Category theory is the slickest of mathematics, under an informal, subjective ordering of mine. Mathematical logic is pretty damn slick too, but it has more primitives and so is less elegant. In different words, it is more computational than category theory, which is compositional by design) I am not sure what you don't understand, so I will start at the beginning, at least in broad strokes. So, going back to the "basic" theory of logic, you have axiomatizations, theories, and models. An axiomatization is a "chosen" finite a set of sentences (it's up to you to pick axioms that encode truths about what you want to study/program). A theory is a set of sentences which is closed under logical implication, and a model is a set of objects[1] which "satisfies" an axiomatization (equivalently, the theory generated by an axiomatization, because of the compactness theorem) In order to make an axiomatization "more specific", you add axioms. In order to make it "more general", you drop axioms. So, every group is a monoid, but not vice-versa: the non-associative monoid of subtraction over the integers is not a group. The monoid does not satisfy the axiom of associativity, and so must be excluded from the class of models for the group axioms. Again, theories are "the same way", but you have to deal with logical closure. I mean, if I was to remove a sentence from a theory, it *might* still generate the same theory, because the sentence I removed was a logical consequence of the others. For example, we can have a theory of arithmetic where an axiom states that 1 + 1 = 2, in addition to the Peano axioms. If we drop the 1 + 1 = 2 axiom and generate the closure of the new theory, we will see that 1 + 1 = 2 anyway. The notion of "satisfaction" is important. As I said, a model for an axiomatization is (conceptually) a set of objects which satisfies an axiomatization or theory. In short, to show that a model satisfies an axiomatization, you need to provide an interpretation function for the model. (This is what type class instances are for, under the Howard-Curry correspondence) An interpretation is a function which takes a sentence from the axiomatization and an object from the model and maps them to a truth value, under certain consistency constraints. For example, I(a 'and' b) = I(a) "and" I(b), where 'and' is a symbolic notion of conjunction and also "and" is a semantic notion of conjunction. (In particular, an interpretation I is a "proof-to-truth homomorphism", and can potentially be reified as a functor, among other things. Now it gets kind of tricky. There are a few correspondences and facts to put together. First is the Howard-Curry Correspondence theorem, which tells us that in a typed programming language, functions can be re-interpreted as proofs of type-level theorems in a corresponding typed logic. That is, typed programming languages are typed constructive logics. So all the "basic" mathematical logic stuff I have talked about applies. But, I never said where axiomatizations and their models "live" on the programming side. And in fact, models are particularly tricky, because they "live" in "shifting" grounds. For example, any logically consistent theory is its own model! The objects of the model (which the interpretation function interprets) are sentences from the theory the model models. The axioms for the theory are to be declared "true" (with respect to the model), and it is immediately obvious that the "identity functor" offers an interpretation, since I(A and B) exactly equals I(A) and I(B). This is called the "free mode
Re: [Haskell-cafe] Parsec question (new user): unexpected end of input
On Tue, Sep 28, 2010 at 10:35 PM, Peter Schmitz wrote: > I am a new Parsec user, and having some trouble with a relatively > simple parser. > > The grammar I want to parse contains tags (not html) marked by > angle brackets (e.g., ""), with arbitrary text (no angle > brackets allowed) optionally in between tags. > > Tags may not nest, but the input must begin and end with a tag. > > Whitespace may occur anywhere (beginning/end of input, > inside/between tags, etc.), and is optional. > > I think my problem may be a lack of using "try", but I'm not sure > where. > > At runtime I get: > > Error parsing file: "...\sampleTaggedContent.txt" (line 4, column 1): > unexpected end of input > expecting "<" > > The input was: > > stuff > more stuff < tag 3 > even more > > > The code is below. (I'm using Parsec-2.1.0.1.) I don't really want > to return anything meaningful yet; just parse okay. > > Any advice about the error (or how to simplify or improve the code) > would be appreciated. > > Thanks much, > -- Peter > > >> -- Parsers: >> taggedContent = do >> optionalWhiteSpace >> aTag >> many tagOrContent >> aTag >> eof >> return "Parse complete." >> >> tagOrContent = aTag <|> someContent "tagOrContent" >> >> aTag = do >> tagBegin >> xs <- many (noneOf [tagEndChar]) >> tagEnd >> optionalWhiteSpace >> return () >> >> someContent = do >> manyTill anyChar tagBegin >> return () >> >> optionalWhiteSpace = spaces -- i.e., any of " \v\f\t\r\n" >> tagBegin = char tagBeginChar >> tagEnd = char tagEndChar >> >> -- Etc: >> tagBeginChar = '<' >> tagEndChar = '>' > > > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > Here's something I put together: http://hpaste.org/40201/parsec_question_new_user_un?pid=40201&lang_40201=Haskell It doesn't have the whitespace handling you want. The big difference in what I did was that when parsing content, it needs to stop on EOF as well as the signal char. Otherwise it won't allow the document to end :-) Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Retargeting Haskell compiler to embedded/hardware
tomahawkins: > A few years ago I attempted to build a Haskell hardware compiler > (Haskell -> Verilog) based on the Yhc frontent. At the time I was > trying to overcome several problems [1] with implementing a hardware > description language as a light eDSL, which convinced me a proper > compiler may be a better approach. Yhc was recommended as a good > starting point since it had a simpler IR compared with GHC -- at least > at the time. > > I am considering restarting this effort, but this time to target hard > realtime embedded code. What is the recommended compiler to start > from? I need an IR that is post type checking with as much desugaring > as possible, and a code base that is relatively easy to splice and > build. > > My other requirement is not to be bound to IO () for 'main'. The top > level will be a monad, but with different semantics than IO. I would > also like to reuse the standard library, with exception to the values > related to IO. > > What are my options? Have you looked at Clash, the GHC to VHDL compiler? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Relaxing atomicity of STM transactions
Clojure has a commute operator whose semantics seem appropriate to your concerns: http://clojure.org/refs http://richhickey.github.com/clojure/clojure.core-api.html#clojure.core/commute Commute in haskell would be roughly :: TVar a -> (a -> a) -> STM a. The TVar touched by commute does not get marked such that the transaction could retry. Nor is the TVar itself even updated at the time. Rather, it is read, and the result of applying some transform to it is returned. Then, when the transaction commits, the tvar is atomically modified by the function and actually updated. This works if the operation commutes with all other operations performed on the TVar anywhere else that may be running concurrently, and if no essential use (i.e. requiring atomicity) is made of the value returned from commute. Both properties can only be enforced by the discipline of the programmer. I don't know how much discussion there's been in the Clojure community about the utility of commute, as a quick google mainly reveals people trying to either figure it out or explain it. Cheers, Sterl. On Sep 28, 2010, at 7:36 PM, Tom Hawkins wrote: > Thanks for the responses, but I think I should explain a bit more. > I'm not interested in being able to read the live value of a TVar at > any arbitrary time (via. unsafeIOToSTM). But rather I would like > looslyReadTVar to have exactly the same semantics as readTVar, except > that the STM runtime would not reject the transaction if the TVar is > modified by another transaction before the atomic commit takes place. > > Also, as I would be implementing something similar in Atom, I'm not > necessarily interested in a Haskell implementation, but rather if the > programming experience is elevated by these alternative semantics. > > For example: > > incr :: TVar -> STM () > incr a = looslyReadTVar a >>= writeTVar a . (+ 1) > > decr a :: TVar -> STM () > decr a = readTVar a >>= writeTVar a . (- 1) > > If incr and decr where atomically started at the same time with the > same TVar, decr would be rejected if incr completed first, but not the > other way around. The initial reaction may be that this seriously > breaks the atomicity of STM, but there may be cases where this could > be useful. For instance, it allow a computationally expensive > transactions to complete, even if their inputs are constantly being > modified. In the embedded domain, this could be a fault monitor that > reads a bunch of constantly changing sensors. > > -Tom > ___ > 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] Retargeting Haskell compiler to embedded/hardware
2010/9/29 Tom Hawkins : > On Tue, Sep 28, 2010 at 9:20 PM, Shakthi Kannan wrote: >> If you are still at it, you can have a look at Chalmers Lava [1], or >> Kansas Lava [2]. >> Feldspar [3] project targets DSP though. > > These are examples light embedded DSLs, i.e. sophisticated libraries > where you compile, then run the program to generate code. This is not > what I want. Rather, I am looking for advice on how to splice GHC -- > or another implementation -- where I can build a compiler starting > from a type checked, simplified Haskell AST; or better yet, an > unevaluated call graph. Hi Tom, How much of GHC's Haskell do you want? If you are happy with something *similar* to Haskell, did you consider to implement (or reuse if something exists) your own concrete syntax and type checker? I would think those problems are quite lightweight in regard to writing a new backend. Cheers, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe