Re: [Haskell-cafe] Lifting IO actions into Applicatives
On Tue, Oct 01, 2013 at 09:29:00AM +0200, Niklas Haas wrote: On Tue, 1 Oct 2013 02:21:13 -0500, John Lato jwl...@gmail.com wrote: It's not a solution per se, but it seems to me that there's no need for the Monad superclass constraint on MonadIO. If that were removed, we could just have class LiftIO t where liftIO :: IO a - t a and it would Just Work. One concern with this is that it's not exactly clear what the semantics are on LiftIO (is liftIO a liftIO b equal to liftIO (a b) or not?) and the interaction between LiftIO and Applicative/Monad would have to be some sort of ugly ad-hoc law like we have with Bounded/Enum etc. What is this 'ad-hoc law' you are talking about ? Furthermore, you might end up specifying a lot of ‘redundant’ constraints like (Monad m, LiftIO m) that way, just a thing to keep in mind. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Template Haskell and Unit
Hi, I am positive about the following situation, but I can't find any concrete answer on the Web. Can anyone confirm this ? In template-haskell-2.7.0, the following quote [t| () |] appears as a (ConT name), where name is the name for unit. However, in template-haskell-2.8.0, the same quote appears as (TupleT 0). Is this the expected behaviour ? Thanks, Jose -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell and Unit
I can't answer about expected behavior, but I can say that those two constructions should be considered identical by the $(…) splice construct. For better or worse, Template Haskell often offers multiple ways of encoding the same source Haskell phrase, and any code that processes Template Haskell syntax should probably treat the two constructs equivalently. I am not sure I agree that those two constructions should be identical. The Unit type is just a normal type with a single inhabitant: the unit value. How is this related to tuples ? Jose -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Template Haskell
Hi, Is it possible to retrieve all definitions contained in a module using Template Haskell ? Thanks, Jose -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Template Haskell
Thanks, Jose -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Errors with Template Haskell
Hi, In Template Haskell, what is the proper way of signalling an error ? For example, you are generating code and you detect that a given parameter does not fulfill a precondition (e.g., String is empty), and you want to abort compilation with a descriptive error message. Thanks, Jose -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Errors with Template Haskell
Thank you! -- Jose Antonio Lopes Ganeti Engineering Google Germany GmbH Dienerstr. 12, 80331, München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores Steuernummer: 48/725/00206 Umsatzsteueridentifikationsnummer: DE813741370 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Hoogle problems?
It also does not work for me when I try http://www.haskell.org/hoogle But you can cheat ;) Try this one instead http://www.haskell.org/hoogle? I don't know what the problem is; but seeing that some people have it and some people don't, perhaps it's a caching problem... Cheers, Jose On Thu, Aug 01, 2013 at 01:35:08PM +0100, Tom Ellis wrote: On Thu, Aug 01, 2013 at 01:25:22PM +0100, Richard Evans wrote: It still doesn't work when I try it. What URL are you using? http://www.haskell.org/hoogle works fine for me. ___ 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] Template Haskell and Haddock
Hi, Is there a way to access docstrings through Template Haskell ? For example, access the docstring of a function declaration ? Best regards, Jose ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Reify type
Hello everyone, Is there a way to automatically reify a type ? In other words, to do the following: reifyType (LitT ...) = ConT ''LitT ... I am using Template Haskell and I want the generated code to have access to Type datatypes that were available to the Template Haskell code. Cheers, Jose ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reify type
That's exactly what I mean! I'll give it a try. Thanks Michael, Jose ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Reify type
Hello, I am getting the following error message: No instance for (Lift Type) arising from a use of `lift' Possible fix: add an instance declaration for (Lift Type) I have imported Language.Haskell.TH.Instances. Is there anything else I have to do ? Regards, Jose ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Simplest way to learn FRP through use
FRP research http://www.mpi-sws.org/~neelk/ http://www.mpi-sws.org/%7Eneelk/ On 01-06-2013 08:43, Christopher Howard wrote: On 05/31/2013 07:47 PM, Tikhon Jelvis wrote: My favorite mini app is John Conway's game of life. I implemented a version with reactive banana and found it perfect for learning the ideas. I have a simple version of the code up on GitHub if you ever want a nice example to read. I tried to make the code neat rather than worrying about performance or features. Would you be willing to give a URL for that? (To save posterity from the trouble of putting your name in a GitHub search box.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Generalizing unionWithKey, unionWith, ...
Hello everyone, unionWithKey and unionWith have the following types unionWith :: Ord k = (a - a - a) - Map k a - Map k a - Map k a unionWithKey :: Ord k = (k - a - a - a) - Map k a - Map k a - Map k a Since they are implemented by means of mergeWithKey, wouldn't it be possible to generalize these functions to the following types ? unionWith :: Ord k = (a - b - c) - Map k a - Map k b - Map k c unionWithKey :: Ord k = (k - a - b - c) - Map k a - Map k b - Map k c Cheers, Jose -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generalizing unionWithKey, unionWith, ...
Yes! intersectionWith is just what I needed. In any case, coming back to your example, why would you want to use undefined in that particular case? What makes it an interesting example ? Best, Jose On 28-05-2013 12:32, Johannes Waldmann wrote: Jose A. Lopes jose.lopes at ist.utl.pt writes: unionWith :: Ord k = (a - b - c) - Map k a - Map k b - Map k c what should be the result of unionWith undefined (M.singleton False 42) (M.singleton True bar) ? perhaps you mean intersectionWith, which already has the type you want. - J.W. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] List comprehensions with Word8
Hello everyone, I was playing with Word8 and list comprehensions and the following examples came up. I have to admit the behavior looks quite strange because it does not seem to be consistent. Can someone shed some light on reason behind some of these outputs? By the way, I have abbreviated some outputs with ellipsis ... [1..10] :: [Word8] [1,2,3,4,5,6,7,8,9,10] [1..100] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,100] [1..1000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,232] [1..1] :: [Word8] [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] [1..10] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,160] [1..100] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,64] [1..1000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,128] [1..1] :: [Word8] [] [1..10] :: [Word8] [] Thank you, Jose -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsing different types, same typeclass
Hey Chris, Thanks for you reply! So the thing is: I actually had an algebraic data type Action with several constructors, one for each Action. And I was deriving Read so there was no problem there. However, I want to be able to add and remove Actions more easily. That is why I transformed the algebraic data type into a typeclass. Similarly, if you think about Object Oriented programming, I want the flexibility of subclassing, where new subclasses can be added without a problem. The fact that parseAction only works on a finite number of Actions is not problematic for now! So, I would really appreciate your help in overcoming this problem! Best regards, José On 18-11-2012 03:08, Chris Wong wrote: Hello José, So, I have a typeclass Action which defines method run: class Action a where run :: a - Int (snipped) Now, I want to parse either A or B from a String. I was thinking about something like this... parseAction :: (Action a, Read a) = String - a parseAction str | (A `isPrefixOf` str = (read :: String - A) str | (B `isPrefixOf` str = (read :: String - B) str The problem is that when calling parseAction I get ambiguous type constraints. How to implement a parse function for two distinct types that share the same typeclass Action. Because after calling parseAction I don't whether A or B was returned: I only care that they are Action instances so I can call run. The problem with your current type: (Action a, Read a) = String - a is that it actually means: For any type that implements Action and Read, I can convert a string to that type. This is wrong because if a user of your module added another type C, your function wouldn't be able to handle it -- it only knows about A and B. That is what GHC is trying to tell you. How you can solve this problem depends on what you're trying to do. If there is a finite number of actions, you can merge them into a single type and remove the type class altogether: data Action = A Int | B Int deriving (Read, Show) run :: Action - Int run (A x) = x run (B x) = x parse :: String - Action parse = read If you have a possibly unlimited number of possible actions, there are many approaches to this -- including, as Stephen said, existential types. However, it's hard to decide on a proper solution without knowing what you're actually trying to do. Chris Best regards, José ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsing different types, same typeclass
Thanks Stephen. I will try this! On 18-11-2012 17:56, Stephen Tetley wrote: With existentials an extesible version might look like this: {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ScopedTypeVariables #-} ... class Action and datatypes A and B the same as before ... -- some new ones... data C = C Int deriving (Read, Show) instance Action C where run (C n) = n data D = D Int deriving (Read, Show) instance Action D where run (D n) = n The important one: data PolyA = forall a. Action a = PolyA a parseAction :: String - PolyA parseAction str | (A `isPrefixOf` str = PolyA $ (read :: String - A) str | (B `isPrefixOf` str = PolyA $ (read :: String - B) str -- can add new cases | (C `isPrefixOf` str = PolyA $ (read :: String - C) str | (D `isPrefixOf` str = PolyA $ (read :: String - D) str This is extensible to some degree as you can add new cases of different types, but all you can do with these different types is run them to make an Int, so it is equivalent to the second version I gave previously: parseAction :: String - Int parseAction str | (A `isPrefixOf` str = run $ (read str :: A) | (B `isPrefixOf` str = run $ (read str :: B) | (C `isPrefixOf` str = run $ (read str :: C) | (D `isPrefixOf` str = run $ (read str :: D) i.e instead of using an existential type to hold something polymorphic that can be run to produce an Int, just call run at the point of use making an Int. -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parsing different types, same typeclass
Thanks Stephen, that worked out just fine! On 18-11-2012 18:23, Jose A. Lopes wrote: Thanks Stephen. I will try this! On 18-11-2012 17:56, Stephen Tetley wrote: With existentials an extesible version might look like this: {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ScopedTypeVariables #-} ... class Action and datatypes A and B the same as before ... -- some new ones... data C = C Int deriving (Read, Show) instance Action C where run (C n) = n data D = D Int deriving (Read, Show) instance Action D where run (D n) = n The important one: data PolyA = forall a. Action a = PolyA a parseAction :: String - PolyA parseAction str | (A `isPrefixOf` str = PolyA $ (read :: String - A) str | (B `isPrefixOf` str = PolyA $ (read :: String - B) str -- can add new cases | (C `isPrefixOf` str = PolyA $ (read :: String - C) str | (D `isPrefixOf` str = PolyA $ (read :: String - D) str This is extensible to some degree as you can add new cases of different types, but all you can do with these different types is run them to make an Int, so it is equivalent to the second version I gave previously: parseAction :: String - Int parseAction str | (A `isPrefixOf` str = run $ (read str :: A) | (B `isPrefixOf` str = run $ (read str :: B) | (C `isPrefixOf` str = run $ (read str :: C) | (D `isPrefixOf` str = run $ (read str :: D) i.e instead of using an existential type to hold something polymorphic that can be run to produce an Int, just call run at the point of use making an Int. -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe