Re: [Haskell-cafe] Haskell haikus
* Gwern Branwen <[EMAIL PROTECTED]> [2008-12-05 18:18:48-0500] > Hi everyone. So today I finally got around to something long on my > todo list - a compilation of all the Haskell haikus I've seen around! > > It is at http://haskell.org/haskellwiki/Haiku > > But I'm afraid I only have 5, and Google doesn't turn up any more. > > So: does anybody have a haiku I missed? Or even better, is anyone > feeling poetically inspired tonight? :) IIRC, Wouter Swierstra wrote some haikus for Summer of Code issue of The Monad Reader _last year_. -- Roman I. Cheplyaka :: http://ro-che.info/ "Don't let school get in the way of your education." - Mark Twain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Could FDs help usurp an ATs syntactic restriction?
Perhaps this ticket is related? http://hackage.haskell.org/trac/ghc/ticket/714 On Thu, Dec 4, 2008 at 9:38 PM, Nicolas Frisby <[EMAIL PROTECTED]> wrote: > From the error below, I'm inferring that the RHS of the associated > type definition can only contain type variables from the instance > head, not the instance context. I didn't explicitly see this > restriction when reading the GHC/Type_families entry. > > Could perhaps the "a b -> bn" functional dependency of the TypeEq > class lift this restriction for bn? This isn't my ball park, but that > idea has my hopes up :). > > > {-# LANGUAGE TypeFamilies #-} > > import TypeEq > > -- Attempting to encapsulate TypeEq behind an associated type. > > class EQ a b where > type BN a b > > instance TypeEq a b bn => EQ a b where > type BN a b = bn > > > results in an error > > > /tmp/Test.hs:9:16: Not in scope: type variable `bn' > Failed, modules loaded: none. > > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] know a workaround for greedy context reduction?
With these three declarations {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-} class C a where c :: a class C a => D a where d :: a instance C a => D a where d = c ghci exhibits this behavior: *> :t d d :: (C a) => a Where I would prefer "d :: (D a) => a". In my actual examples, the context is much larger and I can't involve overlapping instances. Is there a known workaround? I didn't find a related bug on the GHC trac, and I don't know if other compilers behave in the same way. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Animated line art
You may also want to at least look at RSAGL, in particular I've implemented an arrow transformer that does much of what you describe with threading, although I see that I probably need to go back and work on documentation. The basic idea revolves around giving threads an identity type that implements Eq. The parent thread can cull threads it doesn't want, while the threads themselves can spawn new threads or self-terminate. If a thread spawns a thread ID that already exists, the new duplicate is disregarded (unless you choose to provide a different behaviour). Anonymous threads are implemented using Maybe. Threads have an explicit ultimate input and output type, and can explicitly switch themselves over to another thread with matching input and output types. Both the spawn and switch directives take a continuous input, which is a list or Maybe respectively containing information about what spawn or switch should be dispatched at that moment. Since it's an arrow transformer, you can for example pass messages between threads by layering it on top of a StateArrow. I have also used a StateArrow to accumulate rendering instructions and to manage a transformation matrix context. You talk about adding and removing "things", but I don't think that's a good idea. Rather the thing's existence and disposition is a continuous function within a thread. If it assists with understanding, the StatefulArrow is a stripped down arrow transformer version of the YAMPA arrow, and the other arrows build on that functionality until you get to the FRP arrow. The git repo is browsable here: http://roguestar.downstairspeople.org/gitweb?p=rsagl.git;a=summary Relevant modules are ThreadedArrow, SwitchedArrow, StatefulArrow, FRPBase and FRP. I don't have any 2D support in RSAGL at all. Hopefully this helps and I'd also appreciate any feedback. --Lane ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
G'day all. Thomas Davie wrote: class IEngine a where foo :: a -> String bar :: a -> String -> String "Apfelmus, Heinrich" <[EMAIL PROTECTED]> replied: You don't even need a type class, a simple data type is enough. data Engine = Engine { foo :: IO (), bar :: String -> IO () } There is a tradeoff here, that you should be aware of. 1. Using typeclasses. Pro: It works with the SPECIALIZE pragma. Pro: You can put arbitrary data in the concrete data type which is the instance of IEngine. (If you don't, incidentally, this is called a "traits typeclass".) Con: You can't generate instances of IEngine dynamically at run-time (at least without using unportable unsafeCast# magic). So you're limited to only those implementations that you (possibly dynamically) link in. 2. Using records. Pro: Usually simpler, and using fewer lines of code. Pro: You can generate new "instances" at will, and you're not limited to that which you link in. Con: Usually more explicit arguments passed around. Con: If your methods involve polymorphism, then the record will turn out to have a higher-rank type, which isn't valid Haskell 98. This always works because all object methods expect a "self" argument. That's not true for OO languages which have virtual constructors. Haskell typeclasses support virtual constructors/factory methods just fine, because the "self" type can appear anywhere in the signature, including being the return value. The monad "return" method is one example of this. Cheers, Andrew Bromage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Haskell haikus
You come for magic silver bullets slaying bugs... It is only code! 2008/12/6 Gwern Branwen <[EMAIL PROTECTED]>: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA512 > > Hi everyone. So today I finally got around to something long on my > todo list - a compilation of all the Haskell haikus I've seen around! > > It is at http://haskell.org/haskellwiki/Haiku > > But I'm afraid I only have 5, and Google doesn't turn up any more. > > So: does anybody have a haiku I missed? Or even better, is anyone > feeling poetically inspired tonight? :) > > - -- > gwern > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEAREKAAYFAkk5ttoACgkQvpDo5Pfl1oJ+ygCfdSSBmbgyoOwkG53rKahF2Su1 > 84UAoIOrxGwe3u+WwnKxvKulq1AT4IJS > =+2kH > -END PGP SIGNATURE- > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to define Show [MyType] ?
Am Samstag, 6. Dezember 2008 00:13 schrieb Dmitri O.Kondratiev: > > Thanks everybody for your help! > I tried to implement showList, but get the same error: > > {-- > -- from Prelude: > type *ShowS* = > Stringring>-> > Stringring> *showList* :: [a] -> > ShowSwS> --} > > myShows::ShowS > myShows s = s ++ "\n" > > data ShipInfo = Ship { > name :: String, > kind :: String, > canons :: Int > } deriving Show No, if you derive the Show instance for ShipInfo, it automatically implements the standard showList, too. You have to do it yourself: data ShipInfo = Ship { name :: String, kind :: String, canons :: Int } instance Show ShipInfo where showsPrec p (Ship name kind canons) = ... showList xs = showString (unlines $ map show xs) or whatever you want for showList. However, somebody said it before, the Show instance should not be used for pretty-printing. > > -- I get this error again: > instance (Show [ShipInfo]) where > showList [] = myShows [] > showList (x:xs) = myShows "x" ++ showList xs > > Illegal instance declaration for `Show [ShipInfo]' > (The instance type must be of form (T a b c) > where T is not a synonym, and a,b,c are distinct type variables) > In the instance declaration for `Show [ShipInfo]' > Failed, modules loaded: none. > > -- What am I doing wrong? > Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to define Show [MyType] ?
Dmitri O.Kondratiev wrote: Thanks everybody for your help! I tried to implement showList, but get the same error: That's because you're trying to implement instance Show [MyType], but you have to implement instance Show MyType instead, without the []. Groetjes, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Haskell haikus
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 Hi everyone. So today I finally got around to something long on my todo list - a compilation of all the Haskell haikus I've seen around! It is at http://haskell.org/haskellwiki/Haiku But I'm afraid I only have 5, and Google doesn't turn up any more. So: does anybody have a haiku I missed? Or even better, is anyone feeling poetically inspired tonight? :) - -- gwern -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEAREKAAYFAkk5ttoACgkQvpDo5Pfl1oJ+ygCfdSSBmbgyoOwkG53rKahF2Su1 84UAoIOrxGwe3u+WwnKxvKulq1AT4IJS =+2kH -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Fun with type functions
Pointless Haskell a library for point-free programming with recursion patterns that uses type synonym families to provide a view of data types as the fixed points of functors. It defines two type functions type family PF a :: * -> * -- returns the pattern functor for a data type type family Rep (f :: * -> *) x :: * -- returns the result type of applying a functor to a type argument that can be combined to derive the structurally equivalent sum of products for some type: type F a x = Rep (PF a) x class Mu a where inn :: F a a -> a out :: a -> F a a For Haskell polymorphic lists, we need to define: type instance PF [a] = Const One :+: Const a :*: Id instance Mu [a] where inn (Left _) = [] inn (Right (x,xs)) = x:xs out [] = Left _L out (x:xs) = Right (x,xs) Some of the typical recursion patterns are: hylo :: Functor (PF b) => b -> (F b c -> c) -> (a -> F b a) -> a -> c cata :: (Mu a,Functor (PF a)) => a -> (F a b -> b) -> a -> b ana :: (Mu b,Functor (PF b)) => b -> (a -> F b a) -> a -> b One simple example is the foldr (catamorphism) for calculating the lenght of a list: length :: [a] -> Int length = cata (_L::[a]) f where f = zero \/ succ . snd > length [1,2,3,4] 4 I have promoted the library into a cabal package (pointless-haskell) today and am creating an homepage ( http://haskell.di.uminho.pt/wiki/Pointless+Haskell) with examples. cheers, hugo On Thu, Nov 27, 2008 at 9:29 AM, Simon Peyton-Jones <[EMAIL PROTECTED]>wrote: > Friends > > GHC has embodied data type families since 6.8, and now type synonym > families (aka type functions) in 6.10. However, apart from our initial > papers there isn't much published material about how to *use* type families. > But that hasn't stopped you: quite a few people are using them already, and > of course there is a rich seam of work on using functional dependencies to > express type-level computation. > > Ken Shan and Oleg Kiselyov and I are collaborating to write a paper for an > upcoming workshop, under the general rubric of "Fun with type functions" (in > homage to Thomas Hallgren's paper "Fun with functional dependencies" and > Ralf Hinze's paper "Fun with phantom types"). > > So this message is to ask you: > >can you tell us about the most persuasive, fun application >you've encountered, for type families or functional dependencies? > > Simple is good. It doesn't have to be elaborate: just something that does > something useful you could not have done otherwise. Pointers to email > threads are fine. Don't assume we already know about them (even if we > participated in the thread :-) Part of what we're interested in is that > *you* found the example compelling. > > Many thanks > > Simon, Ken, Oleg > > PS: I'm broadcasting this message to GHC-users and Haskell-cafe, but to > avoid deluging ghc-users, please reply just to us and Haskell cafe. > (Interested ghc-users can follow the threads there from the archives if > they want.) > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > -- www.di.uminho.pt/~hpacheco ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Animated line art
On 06/12/2008, at 6:34 AM, Andrew Coppin wrote: Ben Lippmeier wrote: The ANUPlot graphics library I wrote does exactly this. The darcs repo is at http://code.haskell.org/ANUPlot/ANUPlot-HEAD/ It comes with lots of examples that do the sort of things you describe. Does it handle drawing lines and circles (with antialiasing)? Can I save the output as PNG? Lines and circles yes, antialiasing no. It uses OpenGL for rendering, so maybe there's a flag to turn it on. PNG isn't usually required for animations. When I need to make an image I just do a screenshot. Ben. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to define Show [MyType] ?
On Fri, Dec 5, 2008 at 1:29 AM, Martijn van Steenbergen < [EMAIL PROTECTED]> wrote: > Dmitri O.Kondratiev wrote: > >> -- How to define Show [MyType] ? >> > > Define instance Show MyType and implement not only show (for 1 value of > MyType) but also showList, which Show provides as well. You can do all the > magic in there. > > HTH, > > Martijn. > > Thanks everybody for your help! I tried to implement showList, but get the same error: {-- -- from Prelude: type *ShowS* = String-> String *showList* :: [a] -> ShowS --} myShows::ShowS myShows s = s ++ "\n" data ShipInfo = Ship { name :: String, kind :: String, canons :: Int } deriving Show -- I get this error again: instance (Show [ShipInfo]) where showList [] = myShows [] showList (x:xs) = myShows "x" ++ showList xs Illegal instance declaration for `Show [ShipInfo]' (The instance type must be of form (T a b c) where T is not a synonym, and a,b,c are distinct type variables) In the instance declaration for `Show [ShipInfo]' Failed, modules loaded: none. -- What am I doing wrong? Thanks! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] efficient combination of foldl' and foldr -> foldl'r
Hi, Am Freitag, den 05.12.2008, 23:43 +0100 schrieb Henning Thielemann: > > ryani$ ghci foldlr.hs > > [...] > > Prelude FoldLR> :set +s > > Prelude FoldLR> test > > (100,'a') > > (0.39 secs, 70852332 bytes) > > Prelude FoldLR> testNaive > > (100,'a') > > (0.42 secs, 105383824 bytes) > > There is still no clear advantage of foldl'r compared to foldl'rNaive, is > it? Maybe not directly speed-wise, but the memory consumption is reduced by 30% (probably due to laziness, and unless I misreading ghci’s output) Greetings, Joachim -- Joachim "nomeata" Breitner mail: [EMAIL PROTECTED] | ICQ# 74513189 | GPG-Key: 4743206C JID: [EMAIL PROTECTED] | http://www.joachim-breitner.de/ Debian Developer: [EMAIL PROTECTED] signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Can't cabal install readline
On Fri, Dec 5, 2008 at 2:08 PM, Judah Jacobson <[EMAIL PROTECTED]>wrote: > On Fri, Dec 5, 2008 at 1:10 PM, Martijn van Steenbergen > <[EMAIL PROTECTED]> wrote: > > Hello, > > > > This week I upgraded to GHC 6.10 using the .pkg installer. It installed > > without a single hiccup -- thanks! > > > > I've noticed two odd things: the standard library haddock that comes with > > the installer doesn't have links to the hs-coloured sources anymore (and > > neither does the online documentation); I miss that a lot. I also can't > > Ctrl+R anymore in GHCi to search my command history. But I can learn to > live > > without those. > > The following instructions should re-enable Ctrl-R: > > http://mult.ifario.us/p/editrc-tidbit-for-ghci > > > Another minor inconvenience is that the packages I had installed (using > > cabal) are no longer available to GHC -- I think I will have to > reinstall > > them. But I cannot continue working on my Yogurt project anymore, because > it > > depends on readline, which fails to build: > > > > > > checking for rl_readline_version... yes > > checking for rl_begin_undo_group... no > > configure: error: readline not found, so this package cannot be built > > See `config.log' for more details. > > cabal: Error: some packages failed to install: > > Yogurt-0.2 depends on readline-1.0.1.0 which failed to install. > > readline-1.0.1.0 failed during the configure step. The exception was: > > exit: ExitFailure 1 > > > The above happens because GHC is using the OS X default installation > of libreadline.a which is actually a link to libedit that doesn't > implement the full readline API. > > If you already have the MacPorts readline, you just need to tell cabal > where it is, with (for example) > > cabal install readline --extra-include-dirs=/opt/local/include > --extra-lib-dirs=/opt/local/lib > If you'd like, you can add /opt/local/include to your shell's INCLUDE_PATH and/or C_INCLUDE_PATH environment variables and /opt/local/lib to your LIBRARY_PATH and/or LD_LIBRARY_PATH variables. I say "and/or" because I don't know which one is actually necessary, but if you add it to both you'll be safe. - Phil > > -Judah > ___ > 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] efficient combination of foldl' and foldr -> foldl'r
On Fri, 5 Dec 2008, Ryan Ingram wrote: You're testing the interpreted code, so it's not surprising that the naive version performs better; the interpretive overhead only applies to your bit of glue code. I wanted to avoid the optimizer to do clever things itself. Alternatively, at least compile the module with optimizations before running it in ghci: ryani$ ghc -ddump-simpl -O2 -c foldlr.hs >foldlr.core (This gives you "functional assembly language" to look at for examining code generation) ryani$ ghci foldlr.hs [...] Prelude FoldLR> :set +s Prelude FoldLR> test (100,'a') (0.39 secs, 70852332 bytes) Prelude FoldLR> testNaive (100,'a') (0.42 secs, 105383824 bytes) There is still no clear advantage of foldl'r compared to foldl'rNaive, is it? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Gluing pipes
On Fri, Dec 5, 2008 at 11:35 AM, Stefan Monnier <[EMAIL PROTECTED]> wrote: >> \ x y -> f (g x) (h y) > [...] >> f $. g ~> h ~> id > > I keep help wonder: other than a "5 chars", what is it we have gained? Certainly in such a simple case, there's no benefit. In more complex cases, especially where we're focused on just writing the combinator itself (i.e., in cases where we won't use ($.)), I think it might make sense (there is an example in the comments of Conal's recent post at [1]). But anyway I do mean "might"... I happily admit the possibility that this may be nothing more than a curiosity. I'm happy to have found a solution to my little puzzle, but I'm not sure how often I'll actually use it. Time will tell, I suppose. Matt ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Can't cabal install readline
On Fri, Dec 5, 2008 at 1:10 PM, Martijn van Steenbergen <[EMAIL PROTECTED]> wrote: > Hello, > > This week I upgraded to GHC 6.10 using the .pkg installer. It installed > without a single hiccup -- thanks! > > I've noticed two odd things: the standard library haddock that comes with > the installer doesn't have links to the hs-coloured sources anymore (and > neither does the online documentation); I miss that a lot. I also can't > Ctrl+R anymore in GHCi to search my command history. But I can learn to live > without those. The following instructions should re-enable Ctrl-R: http://mult.ifario.us/p/editrc-tidbit-for-ghci > Another minor inconvenience is that the packages I had installed (using > cabal) are no longer available to GHC -- I think I will have to reinstall > them. But I cannot continue working on my Yogurt project anymore, because it > depends on readline, which fails to build: > > > checking for rl_readline_version... yes > checking for rl_begin_undo_group... no > configure: error: readline not found, so this package cannot be built > See `config.log' for more details. > cabal: Error: some packages failed to install: > Yogurt-0.2 depends on readline-1.0.1.0 which failed to install. > readline-1.0.1.0 failed during the configure step. The exception was: > exit: ExitFailure 1 The above happens because GHC is using the OS X default installation of libreadline.a which is actually a link to libedit that doesn't implement the full readline API. If you already have the MacPorts readline, you just need to tell cabal where it is, with (for example) cabal install readline --extra-include-dirs=/opt/local/include --extra-lib-dirs=/opt/local/lib -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Can't cabal install readline
Hello, This week I upgraded to GHC 6.10 using the .pkg installer. It installed without a single hiccup -- thanks! I've noticed two odd things: the standard library haddock that comes with the installer doesn't have links to the hs-coloured sources anymore (and neither does the online documentation); I miss that a lot. I also can't Ctrl+R anymore in GHCi to search my command history. But I can learn to live without those. Another minor inconvenience is that the packages I had installed (using cabal) are no longer available to GHC -- I think I will have to reinstall them. But I cannot continue working on my Yogurt project anymore, because it depends on readline, which fails to build: checking for rl_readline_version... yes checking for rl_begin_undo_group... no configure: error: readline not found, so this package cannot be built See `config.log' for more details. cabal: Error: some packages failed to install: Yogurt-0.2 depends on readline-1.0.1.0 which failed to install. readline-1.0.1.0 failed during the configure step. The exception was: exit: ExitFailure 1 The build failure mentions config.log which I cannot find anywhere on my system. I have readline installed using MacPorts without problems, and the cabal package worked fine too on the previous version of GHC. I'm on Intel Leopard. How can I get cabal install readline to succeed on the new GHC? Thanks much, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
sending email via gmail Re: [Haskell-cafe] Sending email from a Haskell program
I ran into this problem when I wanted to send email from a HAppS web app, routing it through gmail. There actually used to be an SMTP client in HAppS but it was dropped a while ago. The most common workaround appears to be, just use sendmail. But I couldn't figure out a way to get sendmail to interface with gmail. (I think there is a way, there are blogs on it, I just wasn't patient enough to follow the directions.) What I finally did is, I have successfully followed the instructions in http://www.ericstockwell.com/?p=3 to send myself email from the command line. So I will probably use HSH to run shell commands in my haskell web apps, to send email. This process only took a few minutes, and seemed easier than the postfix/sendmail solutions I came across. Of course, this only works in unixy environments. thomas. 2007/9/27 brad clawsie <[EMAIL PROTECTED]>: >> jmuk's HaskellNet project from last year? >> >> http://darcs.haskell.org/SoC/haskellnet/HaskellNet/IMAP.hs > > sweet! was there any documentation created for this? examples? > anything? have people tried to make this work with ssl/tls libs? > > by the way there looks like some other gems in the haskellnet > dir. what exactly was haskellnet - a project to code to the major > network protocols? are these libs stable? how does the HTTP lib stack > up against Network.HTTP? any info on this project would be > appreciated. > ___ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: deleting spam on the wiki
I already added the category "Pages to be removed" to these pages, so they turn up on page: http://haskell.org/haskellwiki/Category:Pages_to_be_removed There are are other pages in this category. Regards, Henk-Jan van Tuyl -- http://functor.bamikanarie.com http://Van.Tuyl.eu/ -- On Fri, 05 Dec 2008 20:36:44 +0100, Ashley Yakeley <[EMAIL PROTECTED]> wrote: You can blank the page but you cannot delete it. I'll delete the pages and block the user/IP address later today. -- Ashley On Fri, 2008-12-05 at 15:37 +, Duncan Coutts wrote: Who is able to delete wiki spam? http://haskell.org/haskellwiki/?title=Special:Contributions&target=Tomso123 All the pages created by this user appear to be spam (check the google translation) so the account should probably be deleted too. As I understand it, any registered user can revert changes to a page: http://www.haskell.org/haskellwiki/Help:Editing However if a registered user creates new spam pages then other ordinary registered users cannot revert that change. Is there some way of reporting spam pages to the appropriate people that I missed? Duncan -- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Animated line art
Today I sat down and had a think about this problem. After reading about various FRP systems (Yampa et al) I had a few ideas in my head. The main idea is that I want to be able to draw lines and curves and so forth, and I want to add them to and remove them from the display at various times, and move them around, change their colour and opacity, etc. I also want to be able to run one piece of animation, and then another, and then another. So I want some sort of sequencing primitives. I had a go at writing what I thought the interface might look like. (Fortunately, I made no attempt to *implement* it - otherwise I would doubtless have wasted huge amounts of time implementing something that isn't designed right yet!) Unfortunately Haskell doesn't really provide a way to write an "interface", and then write the implementation behind it seperately somewhere else. So the "code" I wrote wasn't actually compilable at all, but it was useful to sketch something out. My initial idea was that I could have some kind of monad for controlling adding and removing stuff. The monad could provide an "add" action that adds a visual object to the frame and returns a unique ID. Then you could have a "remove" action that removes the specified ID again. And a "wait" action that makes the display stay the same for so many seconds. (But the visual objects may internally be animated.) Then I hit upon the idea that maybe one thread of control could "spawn" a second one - so that for example one thread could generate a bunch of snowflakes raining down the screen while a seperate thread rotates a geometric figure in the center. Or something. Of course, these "threads" have no need (or use) for actually running concurrently - they are only "concurrent" in the sence that they both affect the same frame, rather than their actions happening one after another on consecutive frames. Next I got to thinking that maybe these threads of control might need to communicate for synchronisation. E.g., when a rotating line reaches 90° with another line, a signal is sent to another thread, which then adds another visual element or stops the animation or something. The parent thread *could* algebraicly _compute_ what time this will happen, but sending a signal is much simpler. (E.g., if you change the speed of an animation, the threads still stay synchronised without you having to remember to adjust parameters in your calculations all over the place...) There's still one little problem though. The "threads of control" are for sequencing stuff. They are inherantly discrete; *add* this thing, *remove* this other thing, *send* this signal, *wait* to receive a signal, etc. But something like, say, rotating a line, is inherantly continuous. So there's a discrete system for sequencing stuff - which I seem to have worked out fairly well - and there also needs to be a continuous system for doing all the things with are smooth functions of time. So maybe the continuous stuff should just be a type alias to a regular Haskell function? Ah, but wait... I said I might want to send a signal when an animation reaches a specific stage, right? So these "functions" need to do more than just map time to some other variable; they need to be able to send signals. And hey, actually, what are the chances of a time sample exactly lining up with the instant that the notable event occurs? How do I want to handle that? ...and at this point, it was time to go home! :-D ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: deleting spam on the wiki
You can blank the page but you cannot delete it. I'll delete the pages and block the user/IP address later today. -- Ashley On Fri, 2008-12-05 at 15:37 +, Duncan Coutts wrote: > Who is able to delete wiki spam? > > http://haskell.org/haskellwiki/?title=Special:Contributions&target=Tomso123 > > All the pages created by this user appear to be spam (check the google > translation) so the account should probably be deleted too. > > As I understand it, any registered user can revert changes to a page: > http://www.haskell.org/haskellwiki/Help:Editing > > However if a registered user creates new spam pages then other ordinary > registered users cannot revert that change. > > Is there some way of reporting spam pages to the appropriate people that > I missed? > > Duncan > > ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Animated line art
Ben Lippmeier wrote: The ANUPlot graphics library I wrote does exactly this. The darcs repo is at http://code.haskell.org/ANUPlot/ANUPlot-HEAD/ It comes with lots of examples that do the sort of things you describe. Does it handle drawing lines and circles (with antialiasing)? Can I save the output as PNG? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Animated line art
Tim Docker wrote: Someone else already mentioned FRAN and it's ilk. But perhaps you don't need something that fancy. If you implement your drawing logic as a function from time to the appropriate render actions, ie | import qualified Graphics.Rendering.Cairo as C | | type Animation = Time -> C.Render () then you just need to call this function multiple times to generate sucessive frames. That was my initial idea... but I'm not sure how well it would work. I want to do stuff like fade elements in and out, move complex structures around on the screen, etc. I think it might end up being a little tangled if I go with this approach. I might be wrong though... ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Animated line art
Martijn van Steenbergen wrote: Andrew Coppin wrote: It seems that the "correct" course of action is to design a DSL for declaratively describing animated line art. Does anybody have ideas about what such a thing might look like? You could take a look at Fran [1] and Yampa [2] which both seem to do animations in Haskell. [1] http://conal.net/Fran/ [2] http://www.haskell.org/yampa/ I don't think either of them will do precisely what I want, but they give me lots of useful stuff to think about. PS. The flying heads were disturbing though. PPS. "Yampa is still in active development. [...] This page last updated March 22 2004." ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] efficient combination of foldl' and foldr -> foldl'r
You're testing the interpreted code, so it's not surprising that the naive version performs better; the interpretive overhead only applies to your bit of glue code. So, you've succeeded in showing that compiled code performs better than interpreted code, congratulations! :) A better test would be to write "main" that does the calculation and compile with -O2. You can then use plain old command line tools to test the timing. Alternatively, at least compile the module with optimizations before running it in ghci: ryani$ ghc -ddump-simpl -O2 -c foldlr.hs >foldlr.core (This gives you "functional assembly language" to look at for examining code generation) ryani$ ghci foldlr.hs [...] Prelude FoldLR> :set +s Prelude FoldLR> test (100,'a') (0.39 secs, 70852332 bytes) Prelude FoldLR> testNaive (100,'a') (0.42 secs, 105383824 bytes) -- ryan On Fri, Dec 5, 2008 at 7:04 AM, Henning Thielemann <[EMAIL PROTECTED]> wrote: > > I want to do a foldl' and a foldr in parallel on a list. I assumed it would > be no good idea to run foldl' and foldr separately, because then the input > list must be stored completely between the calls of foldl' and foldr. I > wanted to be clever and implemented a routine which does foldl' and foldr in > one go. But surprisingly, at least in GHCi, my clever routine is less > efficient than the naive one. > > Is foldl'rNaive better than I expect, or is foldl'r worse than I hope? > > > module FoldLR where > > import Data.List (foldl', ) > import Control.Arrow (first, second, (***), ) > > foldl'r, foldl'rNaive :: > (b -> a -> b) -> b -> (c -> d -> d) -> d -> [(a,c)] -> (b,d) > > foldl'r f b0 g d0 = > first ($b0) . > foldr (\(a,c) ~(k,d) -> (\b -> k $! f b a, g c d)) (id,d0) > > foldl'rNaive f b g d xs = > (foldl' f b *** foldr g d) $ unzip xs > > test, testNaive :: (Integer, Char) > test = > second last $ foldl'r (+) 0 (:) "" $ replicate 100 (1,'a') > {- > *FoldLR> test > (100,'a') > (2.65 secs, 237509960 bytes) > -} > > > testNaive = > second last $ foldl'rNaive (+) 0 (:) "" $ replicate 100 (1,'a') > {- > *FoldLR> testNaive > (100,'a') > (0.50 secs, 141034352 bytes) > -} > > ___ > 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] instance Applicative f => Applicative (StateT s f)
> This makes me wonder: does that mean there is no such thing as an > applicative transformer? Applicative functors compose much more simply than monads, so you don't need transformers. > newtype Compose f g a = O (f (g a)) > unO (O x) = x > instance (Functor f, Functor g) => Functor (Compose f g) where > fmap f o = O $ fmap (fmap f) $ unO o > instance (Applicative f, Applicative g) => Applicative (Compose f g) where >pure x = O $ pure $ pure x > >-- unO of :: f (g (a -> b)) >-- unO ox :: f (g a) >-- to get result :: f (g b) >-- we need to lift of to f (g a -> g b) >-- which we do via (fmap (<*>)) :: f (g (a -> b)) -> f (g a -> g b) >of <*> ox = O ((<*>) <$> unO of <*> unO ox) Prettier implementations of this are available in the TypeCompose library. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Applicative f => Applicative (StateT s f)
On Fri, Dec 05, 2008 at 06:52:31PM +0100, Martijn van Steenbergen wrote: > Ross Paterson wrote: >> Yes, because you need part of the value generated by the first computation, >> namely the state (inside the f), to construct the second one. You can do >> that in a Monad, but not in an Applicative. > > This makes me wonder: does that mean there is no such thing as an > applicative transformer? StateT isn't an applicative transformer, but ErrorT, ReaderT and WriterT are, and there are others that don't correspond to monad transformers, starting with product and composition. The accumulating exceptions applicative (originally due to Duncan Coutts) generalizes to a transformer. Underneath the permutation phrase parser of Arthur Baars, Andres Löh and Doaitse Swierstra is an applicative transformer. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Applicative f => Applicative (StateT s f)
On Fri, Dec 05, 2008 at 06:56:46PM +0100, Thomas Davie wrote: > Which reminds me ofc, that there is a valid applicative for states > (assuming the monad instance is valid): > > instance Applicative (StateT s f) where > pure = return > (<*>) = ap > > All monads are also applicatives ;) Sure, as long as you add the assumption Monad f. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
On Fri, 2008-12-05 at 18:50 +0100, Thomas Davie wrote: > On 5 Dec 2008, at 17:46, Duncan Coutts wrote: > > > On Fri, 2008-12-05 at 17:06 +0100, Thomas Davie wrote: > >> On 5 Dec 2008, at 17:00, Duncan Coutts wrote: > >> > >>> On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: > >>> > Sure, and he could then use a fold instead of a map. Reading files > is > problematic, but as long as you're only doing it once (the most > common > situation) is entirely fine wrapped up in an unsafePerformIO. > >>> > >>> No! > >>> > >>> Please don't go telling people it's entirely fine to use > >>> unsafePerformIO > >>> like that (or at all really). > >> > >> Exactly what isn't fine about it? > > > > It's the antithesis of pure functional programming. It's so unsafe > > that > > we don't even have a semantics for it. > Yes, but we also don't have semantics for IO, so it's no real surprise > that we have none for something that runs an IO action. We don't have a (denotational) semantics for Haskell, either. But, in principle, one could be produced if desired. The pure subset is easy; IO only requires a semantics for the underlying OS and --- in the presence of the FFI --- the C language. Unless you add unsafePerformIO or evaluate to the language. I think that, if someone was sufficiently motivated to work out the details, that you could prove that there is *no* denotational semantics for IO which admits either function without changing the definition of one or more pure Haskell types. jcc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Gluing pipes
Hello Stefan, Friday, December 5, 2008, 8:35:18 PM, you wrote: >> \ x y -> f (g x) (h y) > [...] >> f $. g ~> h ~> id > I keep help wonder: other than a "5 chars", what is it we have gained? Haskell programmers would be paid more :D -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Applicative f => Applicative (StateT s f)
That would be incompatible with the ap of the monad where it exists, but it's worse than that. Which state will you return? If you return one of the states output by one or other of the arguments, you'll break one of the laws: pure id <*> v = v u <*> pure y = pure ($ y) <*> u You're forced to return the input state, so the Applicative would just be an obfuscated Reader. Which reminds me ofc, that there is a valid applicative for states (assuming the monad instance is valid): instance Applicative (StateT s f) where pure = return (<*>) = ap All monads are also applicatives ;) Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Applicative f => Applicative (StateT s f)
Ross Paterson wrote: Yes, because you need part of the value generated by the first computation, namely the state (inside the f), to construct the second one. You can do that in a Monad, but not in an Applicative. This makes me wonder: does that mean there is no such thing as an applicative transformer? Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
On 5 Dec 2008, at 17:46, Duncan Coutts wrote: On Fri, 2008-12-05 at 17:06 +0100, Thomas Davie wrote: On 5 Dec 2008, at 17:00, Duncan Coutts wrote: On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: Sure, and he could then use a fold instead of a map. Reading files is problematic, but as long as you're only doing it once (the most common situation) is entirely fine wrapped up in an unsafePerformIO. No! Please don't go telling people it's entirely fine to use unsafePerformIO like that (or at all really). Exactly what isn't fine about it? It's the antithesis of pure functional programming. It's so unsafe that we don't even have a semantics for it. Yes, but we also don't have semantics for IO, so it's no real surprise that we have none for something that runs an IO action. One needs pretty special justification for using unsafePerformIO and such cases should be hidden in libraries presenting pure interfaces, not used willy-nilly in general application code. Note that I'm not claiming that it's necessarily going to do bad things in the specific case you're imagining using it in. However just because it happens not to do bad things in this case does not mean that it's ok to use it here or in general. No, and I never said that it should be used more generally -- I was very careful that in this case I was following the rules for making sure that verifyItsSafeYourselfPerformIO was indeed safe. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Gluing pipes
> \ x y -> f (g x) (h y) [...] > f $. g ~> h ~> id I keep help wonder: other than a "5 chars", what is it we have gained? Stefan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Applicative f => Applicative (StateT s f)
On Fri, Dec 05, 2008 at 04:59:04PM +0100, Thomas Davie wrote: > > On 5 Dec 2008, at 16:54, Ross Paterson wrote: > >> On Fri, Dec 05, 2008 at 04:35:51PM +0100, Martijn van Steenbergen >> wrote: >>> How do I implement the following? >>> >>> instance Applicative f => Applicative (StateT s f) >>> >>> The implementation of pure is trivial, but I can't figure out an >>> implementation for <*>. Is it possible at all, or do I need to >>> require f >>> to be a monad? >> >> Yes, because you need part of the value generated by the first >> computation, >> namely the state (inside the f), to construct the second one. You can >> do >> that in a Monad, but not in an Applicative. > > I don't think that's true, although I'm yet to decide if Applicative for > State is possible. > > someState <*> someOtherState should take the value out of the first > state, take the value out of the second state, apply one to the other, > and return a new stateful value as the result. At no point in that > description do I make mention of the previous state of one of these > values. That would be incompatible with the ap of the monad where it exists, but it's worse than that. Which state will you return? If you return one of the states output by one or other of the arguments, you'll break one of the laws: pure id <*> v = v u <*> pure y = pure ($ y) <*> u You're forced to return the input state, so the Applicative would just be an obfuscated Reader. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to define Show [MyType] ?
Jules Bean schrieb: > Dmitri O.Kondratiev wrote: >> I am trying to define instance Show[MyType] so >> show (x:xs :: MyType) would return a single string where substrings >> corresponding to list elements will be separated by "\n". >> This would allow pretty printing of MyType list in several lines >> instead of one, as default Show does for lists. > > You're doing it wrong. > > Show is not for pretty-printing. (+1) > Show is for the production of haskell syntax for debugging and > copy-pasting into test cases, as well as for use with 'Read'. > > If you want to pretty print, use a different function name. Maybe related: http://www.haskell.org/haskellwiki/List_instance ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
On Fri, 2008-12-05 at 17:06 +0100, Thomas Davie wrote: > On 5 Dec 2008, at 17:00, Duncan Coutts wrote: > > > On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: > > > >> Sure, and he could then use a fold instead of a map. Reading files > >> is > >> problematic, but as long as you're only doing it once (the most > >> common > >> situation) is entirely fine wrapped up in an unsafePerformIO. > > > > No! > > > > Please don't go telling people it's entirely fine to use > > unsafePerformIO > > like that (or at all really). > > Exactly what isn't fine about it? It's the antithesis of pure functional programming. It's so unsafe that we don't even have a semantics for it. One needs pretty special justification for using unsafePerformIO and such cases should be hidden in libraries presenting pure interfaces, not used willy-nilly in general application code. Note that I'm not claiming that it's necessarily going to do bad things in the specific case you're imagining using it in. However just because it happens not to do bad things in this case does not mean that it's ok to use it here or in general. Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
On 5 Dec 2008, at 17:00, Duncan Coutts wrote: On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: Sure, and he could then use a fold instead of a map. Reading files is problematic, but as long as you're only doing it once (the most common situation) is entirely fine wrapped up in an unsafePerformIO. No! Please don't go telling people it's entirely fine to use unsafePerformIO like that (or at all really). Exactly what isn't fine about it? Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
On Fri, 2008-12-05 at 16:50 +0100, Thomas Davie wrote: > Sure, and he could then use a fold instead of a map. Reading files is > problematic, but as long as you're only doing it once (the most common > situation) is entirely fine wrapped up in an unsafePerformIO. No! Please don't go telling people it's entirely fine to use unsafePerformIO like that (or at all really). Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Applicative f => Applicative (StateT s f)
On 5 Dec 2008, at 16:54, Ross Paterson wrote: On Fri, Dec 05, 2008 at 04:35:51PM +0100, Martijn van Steenbergen wrote: How do I implement the following? instance Applicative f => Applicative (StateT s f) The implementation of pure is trivial, but I can't figure out an implementation for <*>. Is it possible at all, or do I need to require f to be a monad? Yes, because you need part of the value generated by the first computation, namely the state (inside the f), to construct the second one. You can do that in a Monad, but not in an Applicative. I don't think that's true, although I'm yet to decide if Applicative for State is possible. someState <*> someOtherState should take the value out of the first state, take the value out of the second state, apply one to the other, and return a new stateful value as the result. At no point in that description do I make mention of the previous state of one of these values. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] instance Applicative f => Applicative (StateT s f)
On Fri, Dec 05, 2008 at 04:35:51PM +0100, Martijn van Steenbergen wrote: > How do I implement the following? > > instance Applicative f => Applicative (StateT s f) > > The implementation of pure is trivial, but I can't figure out an > implementation for <*>. Is it possible at all, or do I need to require f > to be a monad? Yes, because you need part of the value generated by the first computation, namely the state (inside the f), to construct the second one. You can do that in a Monad, but not in an Applicative. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
On 5 Dec 2008, at 16:42, Apfelmus, Heinrich wrote: Thomas Davie wrote: You don't even need a type class, a simple data type is enough. Very true, but I disagree that you've made it functional in any way, IO is all about sequencing things, it's very much not a functional style data Engine = Engine { foo :: IO (), bar :: String -> IO () } This is much nicer done as functions from String -> String Sure, I agree. I was just replicating foo and bar from the OP because I don't know what kind of effect he had in mind. I mean, instead of merely mapping each command in isolation, he could want to accumulate a value or read files or something. Sure, and he could then use a fold instead of a map. Reading files is problematic, but as long as you're only doing it once (the most common situation) is entirely fine wrapped up in an unsafePerformIO. Either way, the question was how to do it functionally, and to do it functionally, and with all of the nice shiny benefits we get with functional code like composibility and orthogonality, you need to do it with String -> String. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Functional version of this OO snippet
Thomas Davie wrote: >> You don't even need a type class, a simple data type is enough. > > Very true, but I disagree that you've made it functional in any way, IO > is all about sequencing things, it's very much not a functional style >> >> data Engine = Engine { foo :: IO (), bar :: String -> IO () } > > This is much nicer done as functions from String -> String Sure, I agree. I was just replicating foo and bar from the OP because I don't know what kind of effect he had in mind. I mean, instead of merely mapping each command in isolation, he could want to accumulate a value or read files or something. Regards, H. Apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] deleting spam on the wiki
Who is able to delete wiki spam? http://haskell.org/haskellwiki/?title=Special:Contributions&target=Tomso123 All the pages created by this user appear to be spam (check the google translation) so the account should probably be deleted too. As I understand it, any registered user can revert changes to a page: http://www.haskell.org/haskellwiki/Help:Editing However if a registered user creates new spam pages then other ordinary registered users cannot revert that change. Is there some way of reporting spam pages to the appropriate people that I missed? Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] instance Applicative f => Applicative (StateT s f)
Hello all, How do I implement the following? instance Applicative f => Applicative (StateT s f) The implementation of pure is trivial, but I can't figure out an implementation for <*>. Is it possible at all, or do I need to require f to be a monad? Thanks in advance, Martijn. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Functional version of this OO snippet
You don't even need a type class, a simple data type is enough. Very true, but I disagree that you've made it functional in any way, IO is all about sequencing things, it's very much not a functional style data Engine = Engine { foo :: IO (), bar :: String -> IO () } run e = processCommand e =<< getLine processCommand e c | "foo" `isPrefixOf` c = foo e >> run e | "bar" `isPrefixOf` c = bar e c >> run e | otherwise= return () This is much nicer done as functions from String -> String, it becomes much more compassable, removes a sequential style from your code and stops processCommand depending on always working with the "run" function making it a bit more orthogonal. data Engine = Engine {foo :: String, bar :: String -> String} run e = unlines . map (proccesCommand e) . lines processCommand e c | "foo" `isPrefixOf` c = foo e | "bar" `isPrefixOf` c = bar e c | otherwise = "" Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Functional version of this OO snippet
Thomas Davie wrote: > Andrew Wagner wrote: > >> Hi all, >> public interface IEngine { >> void foo(); >> void bar(string bah); >> ... >> } >> public class Program { >> public void Run(IEngine engine){ >> while(true){ >>string command = GetLine(); >>if (command.startsWith("foo")){ >> engine.foo(); >>} else if (command.startsWith("bar")){ >> engine.bar(command); >>... >>else break; >> } >> >> In other words, I want to provide the same UI across multiple >> implementations of the engine that actually processes the commands. > > class IEngine a where > foo :: a -> String > bar :: a -> String -> String You don't even need a type class, a simple data type is enough. data Engine = Engine { foo :: IO (), bar :: String -> IO () } run e = processCommand e =<< getLine processCommand e c | "foo" `isPrefixOf` c = foo e >> run e | "bar" `isPrefixOf` c = bar e c >> run e | otherwise= return () This always works because all object methods expect a "self" argument. In other words, all type class translations of OOP classes have the form class IFoo a where method1 :: a -> ... method2 :: a -> ... ... See also http://www.haskell.org/haskellwiki/Existential_type#Using_constructors_and_combinators Regards, H. Apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] efficient combination of foldl' and foldr -> foldl'r
I want to do a foldl' and a foldr in parallel on a list. I assumed it would be no good idea to run foldl' and foldr separately, because then the input list must be stored completely between the calls of foldl' and foldr. I wanted to be clever and implemented a routine which does foldl' and foldr in one go. But surprisingly, at least in GHCi, my clever routine is less efficient than the naive one. Is foldl'rNaive better than I expect, or is foldl'r worse than I hope? module FoldLR where import Data.List (foldl', ) import Control.Arrow (first, second, (***), ) foldl'r, foldl'rNaive :: (b -> a -> b) -> b -> (c -> d -> d) -> d -> [(a,c)] -> (b,d) foldl'r f b0 g d0 = first ($b0) . foldr (\(a,c) ~(k,d) -> (\b -> k $! f b a, g c d)) (id,d0) foldl'rNaive f b g d xs = (foldl' f b *** foldr g d) $ unzip xs test, testNaive :: (Integer, Char) test = second last $ foldl'r (+) 0 (:) "" $ replicate 100 (1,'a') {- *FoldLR> test (100,'a') (2.65 secs, 237509960 bytes) -} testNaive = second last $ foldl'rNaive (+) 0 (:) "" $ replicate 100 (1,'a') {- *FoldLR> testNaive (100,'a') (0.50 secs, 141034352 bytes) -} ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional version of this OO snippet
In other words, I want to provide the same UI across multiple implementations of the engine that actually processes the commands. You can ofc make my reply somewhat more functional by removing the interact from run, and just making it have type IEngine a => a -> String -> String. That way it will be nice and functional and composable and fit into a larger system. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Functional version of this OO snippet
On 5 Dec 2008, at 13:40, Andrew Wagner wrote: Hi all, public interface IEngine { void foo(); void bar(string bah); ... } public class Program { public void Run(IEngine engine){ while(true){ string command = GetLine(); if (command.startsWith("foo")){ engine.foo(); } else if (command.startsWith("bar")){ engine.bar(command); ... else break; } In other words, I want to provide the same UI across multiple implementations of the engine that actually processes the commands. class IEngine a where foo :: a -> String bar :: a -> String -> String run :: IEngine a => a -> IO () run x = interact (unlines . processCommand x . lines) processCommand e c | "foo" `isPrefixOf` c = foo e | "bar" `isPrefixOf` c = bar e c That should about do it. Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Functional version of this OO snippet
Hi all, public interface IEngine { void foo(); void bar(string bah); ... } public class Program { public void Run(IEngine engine){ while(true){ string command = GetLine(); if (command.startsWith("foo")){ engine.foo(); } else if (command.startsWith("bar")){ engine.bar(command); ... else break; } In other words, I want to provide the same UI across multiple implementations of the engine that actually processes the commands. Thanks in advance. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Quickcheck in industry - own experience.
http://writert.blogspot.com/2008/12/quickchecking-code-i-c.html /Gf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] propogation of Error
i would expect to get back the Error from the *first* function in the sequence of functions in checkHeader (oggHeaderError from the oggHeader function). but instead i always see the Error from the *last* function in the sequence, OggPacketFlagError from the OggPacketFlag function. why is this? is there any way i can get the desired behavior...i.e. see the Error from the first function in the sequence that fails? Hi You are essentially asking why this function: checkHeader handle = ((oggHeader handle) >> (oggStreamFlag handle) >> (oggHeaderFlag handle) >> (skipBytes handle 20)>> (oggPageSecCount handle) >> (oggPacketFlag handle)) returns the last error (OggPacketFlagError) instead of the first one. Some type annotations might help you see what is going on. So let's ask ghci the type of, e.g. oggHeaderFlag *File.Ogg> :t oggHeaderFlag oggHeaderFlag :: SIO.Handle -> IO (Either OggParseErrorType [Char]) oggHeaderFlag takes a handle, and computes either an error or a string. But since you are using >>, the computed value is not passed to the next function in the pipe! There is no way checkHeader can stop early simply because it is ignoring the intermediate results altogether. Since you are importing Control.Monad.Error, I believe you would probably want oggHeaderFlag et al to have type: SIO.Handle -> ErrorT OggParseErrorType IO [Char] This will propagate errors correctly. You can see a version of your code using ErrorT here: http://hpaste.org/12705#a1 Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to define Show [MyType] ?
Dmitri O.Kondratiev wrote: I am trying to define instance Show[MyType] so show (x:xs :: MyType) would return a single string where substrings corresponding to list elements will be separated by "\n". This would allow pretty printing of MyType list in several lines instead of one, as default Show does for lists. You're doing it wrong. Show is not for pretty-printing. Show is for the production of haskell syntax for debugging and copy-pasting into test cases, as well as for use with 'Read'. If you want to pretty print, use a different function name. Jules ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunDeps vs. Associated Types
On Fri, 5 Dec 2008, Sebastian Fischer wrote: Dear Haskellers, I have a question regarding the correspondence between functional dependencies and associated types. {-# LANGUAGE TypeFamilies, FlexibleInstances, MultiParamTypeClasses, FunctionalDependencies #-} With associated types, we can define a (useless[^1]) type class class Useless a where type T a useless :: a -> T a and instances instance Useless () where type T () = () useless = id instance Useless a => Useless (() -> a) where type T (() -> a) = T a useless f = useless (f ()) Now we can compute `()` in many different ways: useless () useless (\()->()) ... I thought I could express the same with a multi-parameter type class and a functional dependency: class UselessFD a b | a -> b where uselessFD :: a -> b But the corresponding instances instance UselessFD () () where uselessFD = id instance UselessFD a b => UselessFD (() -> a) b where uselessFD f = uselessFD (f ()) are not accepted (at least by ghc-6.10.1) without allowing undecidable instances: useless.lhs:50:2: Illegal instance declaration for `UselessFD (() -> a) b' (the Coverage Condition fails for one of the functional dependencies; Use -XUndecidableInstances to permit this) In the instance declaration for `UselessFD (() -> a) b' Is there a simple explanation for this? GHC does not implement the same conditions for type families and functional dependencies. Theoretically the same conditions may be used for both. The Coverage Condition is unnecessarily restrictive. A more relaxed condition has been proposed in the literature (JFP paper on using CHRs for FDs; our ICFP'08 paper), which GHC implements for type families but not functional dependencies. -- Tom Schrijvers Department of Computer Science K.U. Leuven Celestijnenlaan 200A B-3001 Heverlee Belgium tel: +32 16 327544 e-mail: [EMAIL PROTECTED] url: http://www.cs.kuleuven.be/~toms/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] FunDeps vs. Associated Types
Dear Haskellers, I have a question regarding the correspondence between functional dependencies and associated types. > {-# LANGUAGE TypeFamilies, > FlexibleInstances, > MultiParamTypeClasses, > FunctionalDependencies > #-} With associated types, we can define a (useless[^1]) type class > class Useless a > where > type T a > useless :: a -> T a and instances > instance Useless () > where > type T () = () > useless = id > > instance Useless a => Useless (() -> a) > where > type T (() -> a) = T a > useless f = useless (f ()) Now we can compute `()` in many different ways: useless () useless (\()->()) ... I thought I could express the same with a multi-parameter type class and a functional dependency: > class UselessFD a b | a -> b > where > uselessFD :: a -> b But the corresponding instances > instance UselessFD () () > where > uselessFD = id > > instance UselessFD a b => UselessFD (() -> a) b > where > uselessFD f = uselessFD (f ()) are not accepted (at least by ghc-6.10.1) without allowing undecidable instances: useless.lhs:50:2: Illegal instance declaration for `UselessFD (() -> a) b' (the Coverage Condition fails for one of the functional dependencies; Use -XUndecidableInstances to permit this) In the instance declaration for `UselessFD (() -> a) b' Is there a simple explanation for this? Cheers, Sebastian [^1]: Originally, I was implementing hidden generation of unique identifiers. So instead of `useless :: (() -> () -> ... -> ()) -> ()` I got something like `withUnique :: (ID -> ... -> ID -> a) -> a`. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe