Re: [Haskell-cafe] TypeLits Typeable
Hi Nicolas, It's not intentional, but Iavor is aware of this, and we want to change it. I'm CC-ing him as he might know more about what the current plan is. Cheers, Pedro On Sat, Aug 24, 2013 at 3:20 PM, Nicolas Trangez nico...@incubaid.comwrote: Hello Cafe, I was playing around with TypeLits in combination with Typeable (using GHC 7.7.7.20130812 FWIW), but was surprised to find Symbols aren't Typeable, and as such the following doesn't work. Is this intentional, or am I missing something? Thanks, Nicolas {-# LANGUAGE DataKinds, KindSignatures, DeriveFunctor, DeriveDataTypeable #-} module Main where import Data.Typeable import GHC.TypeLits data NoSymbol n a b = NoSymbol a b deriving (Typeable) data WithSymbol (n :: Symbol) a b = WithSymbol a b deriving (Typeable) data Sym deriving (Typeable) main :: IO () main = do print $ typeOf (undefined :: NoSymbol Sym Int Int) let d = undefined :: WithSymbol sym Int Int {- print $ typeOf d No instance for (Typeable Symbol sym) arising from a use of 'typeOf' -} return () ___ 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] Rank N Kinds
Hi, On Fri, Jul 26, 2013 at 10:42 PM, Wvv vite...@rambler.ru wrote: First useful use is in Typeable. In GHC 7.8 class Typeable (a::k) where ... == class Typeable (a ::**) where ... But we can't write data Foo (a::k)-(a::k)-* ... deriving Typeable Why not? This works fine in 7.7, as far as I know. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeable typeclass and type-level naturals
Hi, On Wed, Jun 5, 2013 at 11:21 PM, TP paratribulati...@free.fr wrote: José Pedro Magalhães wrote: Oh, it should probably be simply deriving instance Typeable 'Zero deriving instance Typeable 'Succ Yes, that's how it should be. Please let me know if that doesn't work. Thanks, it works perfectly like that. I don't understand exactly why the previous syntax did not work, but maybe it will be clearer when I finish the paper Scrap your boilerplate: a practical design pattern for generic programming (anyway, this paper seems very interesting). It's an interesting paper, but I'm afraid it won't help you understand what's going on. Typeable is changing in GHC 7.8 to become poly-kinded. You are using Typeable instances for things which are not of kind *, so you need this new poly-kinded variant. The SYB paper says nothing about polykinds (it was written way before polykinds came up). You can find some more information on the new Typeable here: http://hackage.haskell.org/trac/ghc/wiki/GhcKinds/PolyTypeable By the way, you can also get those Typeable instances derived automatically if you use the LANGUAGE pragma AutoDeriveTypeable. This is also documented in the HEAD user's guide. Cheers, Pedro Output of the code: - $ runghc-head test_typeable.hs Box test_typeable.hs: Prelude.undefined - Maybe the Box in front of the line is strange, but it is OK: one is undefined, not Box one. This is the full tested code, for sake of reference: --- {-# LANGUAGE GADTs #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE StandaloneDeriving #-} import Data.Typeable data Nat = Zero | Succ Nat deriving ( Show, Eq, Ord ) deriving instance Typeable 'Zero deriving instance Typeable 'Succ data Box where Box :: (Typeable s, Show s, Eq s) = s - Box deriving Typeable data Proxy a = P deriving (Typeable, Show, Eq) deriving instance Show Box instance Eq Box where (Box s1) == (Box s2) = Just s1 == cast s2 main = do let one = undefined :: Main.Proxy ('Succ 'Zero) let foo = Box one print foo -- Thanks a lot, TP ___ 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] Typeable typeclass and type-level naturals
On Wed, Jun 5, 2013 at 8:46 AM, Roman Cheplyaka r...@ro-che.info wrote: * TP paratribulati...@free.fr [2013-06-05 00:37:36+0200] Roman Cheplyaka wrote: Try adding deriving instance Typeable 'Zero deriving instance Typeable a = Typeable ('Succ a) to your module. (I haven't tested it -- you might need to tweak it a bit.) Thanks Roman. Unfortunately, I already tried that (without the constraint Typeable a =, what a fool), but it did not work. The error is the same with the constraint: Derived typeable instance must be of form (Typeable 'Succ) In the stand-alone deriving instance for 'Typeable a = Typeable (Succ a)' What is the problem? Oh, it should probably be simply deriving instance Typeable 'Zero deriving instance Typeable 'Succ Yes, that's how it should be. Please let me know if that doesn't work. (Sorry for taking so long to reply to this...) Cheers, Pedro Roman ___ 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] Derving NFData via Generics from a type that has a vector doesn't work. (was trying to understand out of memory exceptions)
What is the error that you get? Cheers, Pedro On Tue, Apr 16, 2013 at 8:07 PM, Anatoly Yakovenko aeyakove...@gmail.comwrote: -- ok, something in deriving NFData using Generics in a type that has a Vector in it. {-# LANGUAGE DeriveGeneric #-} import Control.DeepSeq import System.IO import GHC.Generics (Generic) import qualified Data.Vector as V import qualified Data.ByteString.Lazy.Char8 as BL scanl' :: NFData a = (a - b - a) - a - [b] - [a] scanl' f q ls = q : (case ls of [] - [] x:xs - let q' = f q x in q' `deepseq` scanl' f q' xs) -- this runs without blowing up -- main = print $ last $ scanl' (+) (0::Int) [0..] data Simple = Simple (V.Vector Double) deriving (Show, Generic) instance NFData Simple --this blows up main = do let initial = Simple $ V.fromList (take 100 $ repeat 0) sumvs (Simple a) (Simple b) = Simple $ V.zipWith (+) a b print $ last $ scanl' sumvs initial $ repeat $ initial ___ 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] Which generic zipper? [RESOLVED]
Hi Luke, Even though you might have made up your mind already, here's some more info. If you want a zipper that does not use Typeable (and thus runtime type comparison and casting, which are potentially inefficient), you can use the zipper in Multirec [1]. Creating a zipper based on GHC.Generics should be easy taking the zipper based on instant-generics [2], or you can just use Sean Leather's rendering [3]. Cheers, Pedro [1] http://hackage.haskell.org/package/multirec [2] http://hackage.haskell.org/package/instant-zipper [3] https://github.com/spl/generic-deriving-extras On Thu, Apr 11, 2013 at 8:44 AM, Luke Evans l...@eversosoft.com wrote: Thanks Roman. I'll probably go with Data.Data then. Certainly, I'm not looking for any significant distractions and I'll heed your cautionary note. I read that GHC.Generics is fit and fast in comparison to SYB, but that's not really a big concern for me at the moment. I just fell in to believing that GHC.Generics was the true religion given its apparent status as the adopted generics in GHC. On 2013-04-10, at 11:24 PM, Roman Cheplyaka r...@ro-che.info wrote: Note that syz is essentially based on Data.Data, which is no less official than GHC.Generics. (The compiler can derive Data with -XDeriveDataTypeable.) You can write a zipper based on GHC.Generics, but it won't be a straightforward translation of syz (nor would it be a trivial undertaking). Roman ___ 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] Optimizing Fold Expressions
Hi, Actually, if you really want folds, you should use regular [1] instead. Here's an example of a generic fold using regular: -- Datatype representing logical expressions data Logic = Var String | Logic :-: Logic -- implication | Logic :-: Logic -- equivalence | Logic :: Logic -- and (conjunction) | Logic :||: Logic -- or (disjunction) | Not Logic -- not | T -- true | F -- false deriving Show -- Instantiating Regular for Logic using TH $(deriveAll ''Logic PFLogic) type instance PF Logic = PFLogic l1, l2, l3 :: Logic l1 = Var p l2 = Not l1 l3 = l1 :-: l2 -- Testing folding ex7 :: Bool ex7 = fold (alg (\_ - False)) l3 where alg env = (env impl (==) () (||) not True False) impl p q = not p || q Cheers, Pedro [1] http://hackage.haskell.org/package/regular-0.3.4.2 On Sat, Mar 30, 2013 at 7:36 PM, Roman Cheplyaka r...@ro-che.info wrote: The solution to this problem is called scrap your boilerplate. There are a few libraries that implement it, in different variations. Let me show you how to do it using my library, 'traverse-with-class'. You'll need install it and the 'tagged' package to run this example. {-# LANGUAGE TemplateHaskell, ImplicitParams, OverlappingInstances, MultiParamTypeClasses, ConstraintKinds, UndecidableInstances #-} import Data.Generics.Traversable import Data.Generics.Traversable.TH import Data.Proxy data Expr = Add Expr Expr | Sub Expr Expr | Mul Expr Expr | Eq Expr Expr | B Bool | I Int deriving Show -- derive a GTraversable instance for our type deriveGTraversable ''Expr -- class to perform our operation class IntToBool a where intToBool :: a - a -- case for expressions: no recursion, we care only about the one level. -- The everywhere function will do recursion for us. instance IntToBool Expr where intToBool (I x) = B $ if x == 0 then False else True intToBool e = e -- default case for non-I constructors -- default case for non-expression types (such as Int): do nothing instance IntToBool a where intToBool = id -- the final implementation replaceIntByBool :: Expr - Expr replaceIntByBool = let ?c = Proxy :: Proxy IntToBool in everywhere intToBool Roman * J. J. W. bsc.j@gmail.com [2013-03-30 19:45:35+0100] Dear all, I was wondering whether it was possible to write fold expressions more elegantly. Suppose I have the following datastructure: data Expr = Add Expr Expr | Sub Expr Expr | Mul Expr Expr | Eq Expr Expr | B Bool | I Int deriving Show type ExprAlgebra r = (r - r - r, -- Add r - r - r, -- Sub r - r - r, -- Mul r - r - r, -- Eq Bool - r, -- Bool Int - r -- Int ) foldAlgebra :: ExprAlgebra r - Expr - r foldAlgebra alg@(a, b, c ,d, e, f) (Add x y) = a (foldAlgebra alg x) (foldAlgebra alg y) foldAlgebra alg@(a, b, c ,d, e, f) (Sub x y) = b (foldAlgebra alg x) (foldAlgebra alg y) foldAlgebra alg@(a, b, c ,d, e, f) (Mul x y) = c (foldAlgebra alg x) (foldAlgebra alg y) foldAlgebra alg@(a, b, c ,d, e, f) (Eq x y) = d (foldAlgebra alg x) (foldAlgebra alg y) foldAlgebra alg@(a, b, c ,d, e, f) (B b')= e b' foldAlgebra alg@(a, b, c ,d, e, f) (I i) = f i If I am correct, this works, however if we for example would like to replace all Int's by booleans (note: this is to illustrate my problem): replaceIntByBool = foldAlgebra (Add, Sub, Mul, Eq, B, \x - if x == 0 then B False else B True) As you can see, a lot of useless identity code. Can I somehow optimize this? Can someone give me some pointers how I can write this more clearly (or with less code?) So I constantly don't have to write Add, Sub, Mul, for those things that I just want an identity function? Thanks in advance! Jun Jie ___ 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] Some aggregation of Haskell content
On Mon, Mar 18, 2013 at 9:56 AM, Christopher Done chrisd...@gmail.comwrote: As a follow up, here's an implementation: http://haskellnews.org/ Could it have an RSS feed? Thanks, Pedro More info here: http://www.reddit.com/r/haskell/comments/1ahgrn/haskell_news/c8xfp9s On 10 February 2013 18:22, Daniel Díaz Casanueva dhelta.d...@gmail.com wrote: I'm totally with this. Also, it is exhausting to check in so many places to see what's going on. I have been looking for this for a while. On Sun, Feb 10, 2013 at 10:41 AM, Christopher Done chrisd...@gmail.com wrote: Is there a page somewhere that aggregates all of Haskell's community output into one place? As a consumer of Haskell content I neither have the time nor inclination to follow haskell-cafe and other various mailing lists, the reddits, the google+ community, planet haskell, hackage releases, twitter, youtube and whatever other submission places I haven't heard of. I made this page for the Lojban community some years ago: http://jbotcan.org/hub/ Lojban doesn't have much community activity (tho this doesn't include mailing list posts), but Haskell's community is much larger and more active, it would be far more useful. I may write such a page for Haskell content, if not for the community then at least for myself, as I keep missing out on cool things because I didn't happen to check out that particular medium of exchange. For example, even this message will be lost on a thousand people who doesn't follow the mailing list but maybe follows G+ or reddit. Kind of like a Haskell Weekly news, except more like Haskell news right now or in some adjustable time frame. And the option to toggle between chronological order or categorized. Ciao! ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- E-mail sent by Daniel Díaz Casanueva let f x = x in x ___ 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] GHC.Generics and newtypes
Hi Roman, Yes, the automatic derivation of Generic instances does not see through newtypes. Cheers, Pedro On Sun, Jan 27, 2013 at 8:17 PM, Roman Cheplyaka r...@ro-che.info wrote: Hi, Is it possible to generate different instances for newtypes and datatypes using GHC.Generics? Roman ___ 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] GHC.Generics and newtypes
Ah, no. But that would be easy to add to the Datatype classhttp://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/GHC-Generics.html#g:3, I think. Perhaps open a feature request? Cheers, Pedro On Sun, Jan 27, 2013 at 8:34 PM, Roman Cheplyaka r...@ro-che.info wrote: Sorry, I wasn't clear. What I want is somehow to find out whether the type under consideration is declared using data or newtype. Is it possible? Roman * José Pedro Magalhães j...@cs.uu.nl [2013-01-27 20:29:52+] Hi Roman, Yes, the automatic derivation of Generic instances does not see through newtypes. Cheers, Pedro On Sun, Jan 27, 2013 at 8:17 PM, Roman Cheplyaka r...@ro-che.info wrote: Hi, Is it possible to generate different instances for newtypes and datatypes using GHC.Generics? Roman ___ 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-derivable Typeable
Won't it derive it with StandaloneDeriving? Cheers, Pedro On Tue, Jan 22, 2013 at 1:28 PM, Roman Cheplyaka r...@ro-che.info wrote: I need to declare a Typeable instance for a type which has an argument of kind * - *. GHC refuses to derive it. What is a recommended way to go about it? In particular, if I write the instance by hand, how important is the fingerprint, and how could I generate it? Roman ___ 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-derivable Typeable
Yes, that will work. But soon we'll have poly-kinded Typeable in HEAD, which will be able to derive that instance. Cheers, Pedro On Tue, Jan 22, 2013 at 2:34 PM, Roman Cheplyaka r...@ro-che.info wrote: I just found mkTyCon3 which generates the fingerprint automatically. (I was looking at Data.Typeable.Internal.mkTyCon before.) That answers my question. (Of course, a way to derive the instance would be even better...) Roman * Roman Cheplyaka r...@ro-che.info [2013-01-22 15:28:55+0200] I need to declare a Typeable instance for a type which has an argument of kind * - *. GHC refuses to derive it. What is a recommended way to go about it? In particular, if I write the instance by hand, how important is the fingerprint, and how could I generate it? Roman ___ 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] Chordify, a new web startup using Haskell
Hi all, Thanks for all the feedback and kind words. Yes, we're planning to have export to PDF/midi options soon. We have plenty of ideas, but limited time :-/ User feedback is collected (and voted for) on https://chordify.uservoice.com/ Thanks, Pedro On Fri, Jan 18, 2013 at 12:37 PM, Rustom Mody rustompm...@gmail.com wrote: On Fri, Jan 18, 2013 at 2:09 PM, Thiago Negri evoh...@gmail.com wrote: Is it possible to play the generated chords as a melody by itself, without the original music over it? Super work! I was meaning to ask something similar -- can we get out something of the music that chordify has reverse engineered -- maybe midi maybe musicxml? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Chordify, a new web startup using Haskell
Hi all, I'd like to introduce Chordify http://chordify.net/ [1], an online music player that extracts chords from musical sources like Soundcloud, Youtube or your own files, and shows you which chord to play when. Here's an example song: http://chordify.net/chords/passenger-let-her-go-official-video-passengermusic The aim of Chordify is to make state-of-the-art music technology accessible to a broader audience. Behind the scenes, Chordify uses the HarmTrace Haskell package to compute chords from audio. I've been working on this project with a couple of colleagues for a while now, and recently we have made the website public, free to use for everyone. We do not use Haskell for any of the frontend/user interface, but the backend is entirely written in Haskell (and it uses pretty advanced features, such as GADTs and type families [3]). We're particularly interested in user feedback at this stage, so if you're interested in music and could use an automatic chord transcription service, please try Chordify! Cheers, Pedro [1] http://chordify.net/ [2] http://hackage.haskell.org/package/HarmTrace [3] José Pedro Magalhães and W. Bas de Haas. Functional Modelling of Musical Harmony: an Experience Report. In Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming (ICFP'11), pp. 156–162, ACM, 2011. http://dreixel.net/research/pdf/fmmh.pdf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Navigating 'Strategic' programming babel
Hi Ravi, You might want to browse through Comparing Libraries for Generic Programming in Haskell: http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-010.pdf SYB and Uniplate are two widely used and well-maintained systems for strategic traversals over arbitrary datatypes. There are other options, too, but it depends on exactly what you want to do. Cheers, Pedro On Mon, Dec 17, 2012 at 11:30 AM, Ravi Sahni ganeshsahn...@gmail.comwrote: Clearly Haskell has great possibilities in the field of language-processing. And the nuisances associated with little actual computation buried under much data-structure navigation are well addressed by 'strategic-programming' systems. But now comes the rub -- there seem to be a lot of very similar systems. Any guidance on which/what/how to choose? My own current sketchy-patchy knowledge is as below. I would appreciate links/pointers to more substansive literature. First there was Meertens and his folks working on generic haskell Did that later become template haskell? That branched out into strafunski, stratego/xt. SYB is ___ not sure here: some literature suggests that its identical to strafunski. Some suggests that it is strafunski done more within the haskell language rather than in libraries. Then there's uniplate. How does it compare to SYB? Or is that a confused comparison? ___ 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 is default method signatures supposed to be used together with Generics
Hi Johan, The error message is not ideal, but it does say that adding a Generic (Foo a) instance might solve the problem. I generally do not export classes like GHashable because they are closed; users should never need to provide more instances themselves. Also, exporting the class won't make the error message any better, and the solution to this error doesn't really involve the GHashable class... Cheers, Pedro On Wed, Dec 12, 2012 at 4:28 AM, Johan Tibell johan.tib...@gmail.comwrote: Hi, I noticed that you're not required to export the types mentioned in the default method signature. For example, you could have: default hashWithSalt :: (Generic a, GHashable (Rep a)) = Int - a - Int hashWithSalt salt = ghashWithSalt salt . from and not export the GHashable class. However, if users try to define an instance of Hashable but forget to derive Generic: data Foo a = Foo a String deriving (Eq) -- Oops, forgot Generic here instance (Hashable a) = Hashable (Foo a) they get a pretty bad error message: Test.hs:10:10: Could not deduce (Generic (Foo a), Data.Hashable.Class.GHashable (GHC.Generics.Rep (Foo a))) arising from a use of `Data.Hashable.Class.$gdmhashWithSalt' from the context (Hashable a) bound by the instance declaration at Test.hs:10:10-41 Possible fix: add (Generic (Foo a), Data.Hashable.Class.GHashable (GHC.Generics.Rep (Foo a))) to the context of the instance declaration or add instance declarations for (Generic (Foo a), Data.Hashable.Class.GHashable (GHC.Generics.Rep (Foo a))) In the expression: (Data.Hashable.Class.$gdmhashWithSalt) In an equation for `hashWithSalt': hashWithSalt = (Data.Hashable.Class.$gdmhashWithSalt) In the instance declaration for `Hashable (Foo a)' Exporting GHashable would help a little bit in that users would at least know what this GHashable class that the error talks about is. What's best practice? -- Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Variable-arity zipWith (re)invented.
Hi Takayuki, Just thought I'd mention another approach to a variadic zipWith, this one using type families: http://typesandkinds.wordpress.com/2012/11/26/variable-arity-zipwith/ The current lack of overlap in type families makes things a bit more complicated, but it can be solved using the upcoming overlapping type families. Cheers, Pedro On Sat, Dec 8, 2012 at 3:27 PM, Takayuki Muranushi muranu...@gmail.comwrote: Continued discussion from https://groups.google.com/d/topic/haskell-cafe/-e-xaCEbd-w/discussion https://groups.google.com/d/topic/haskell-cafe/kM_-NvXAcx8/discussion Thank you for all the answeres and thinkings; Here's zipWithN for general Zip functors: [1] . This, together with [2] may constitute a small hackage. A modification from Wren's idea to [1] is the use of fmap instead of repeat. I'm wondering if there are any laws for Zip functors. I first thought that there are similarity between Zips and Applicatives, as [3] states instance Applicative f = Zip f where zip = liftA2 (,) However, my intuition is that zipping two arrays should result in an array of size of the same order as two, giving rise to a Zip functor law candidate: zipWith const xs $ zipWith const xs ys == zipWith const xs ys which is violated by the above statement zip = liftA2 (,) . [1] https://github.com/nushio3/practice/blob/master/variable-arity/ZipWithN-2.hs [2] https://github.com/nushio3/practice/blob/master/free-objects/zipf-12.hs [3] http://hackage.haskell.org/packages/archive/TypeCompose/0.9.7/doc/html/Data-Zip.html -- Takayuki MURANUSHI The Hakubi Center for Advanced Research, Kyoto University http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html ___ 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] [Security] Put haskell.org on https
+1 Pedro On Sun, Oct 28, 2012 at 12:20 AM, Niklas Hambüchen m...@nh2.me wrote: (I have mentioned this several times on #haskell, but nothing has happened so far.) Are you aware that all haskell.org websites (hackage, HaskellWiki, ghc trac) allow unencrypted http connections only? This means that everyone in the same Wifi can potentially - read you passwords for all of these services - abuse your hackage account and override arbitrary packages (especially since hackage allows everybody to override everything) I propose we get an SSL certificate for haskell.org. I also offer to donate that SSL certificate (or directly create it using my Startcom account). Niklas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Problems translating Conor McBride's talk into Haskell + DataKind + KindPoly
Hi, Please use GHC 7.6 for experimenting with PolyKinds/DataKinds; the implementation in 7.4 was not fully complete. Your code compiles fine in 7.6. Cheers, Pedro On Fri, Oct 26, 2012 at 3:10 AM, Ahn, Ki Yung kya...@gmail.com wrote: Promotion works for user defined lists such as data List a = Nil | Cons a (List a) And, if I use (List Bool) instead of [Bool] everything works out. It's only the Haskell list type constructor [] is being a problem. In the Giving Haskell a promotion paper, it says that Haskell lists are natively promoted. I believe this means that it is treated specially somehow. I don't know how it is implemented but what GHC 7.4.1 does specially for Haskell lists has some problems. So, it's clearly not a limitation of DataKind and PolyKind extension, but that special routine for [] is the issue. I might have to write bug report. On 2012년 10월 25일 18:07, Ahn, Ki Yung wrote: Most part of Conor's talk at ICFP, until just before the last stage where he heavily uses true value dependency for compiler correctness all the code seemed to be able to translate into Haskell with the new hot DataKinds and PolyKinds extension. I tried it in GHC 7.4.1 and it was possible to do it, but I got stuck and I had to make the generic list structure mono-kinded with kind signatures rather not use the PolyKinds extension. I wonder if this is just a but of GHC 7.4.1's implementation of PolyKinds, or a limitation of the DataKind design. I attached a literate Haskell script with this message that illustrates this problem. Thanks in advance for any comments including whether it runs in later versions or still has problems, and discussions about the DataKinds and PolyKinds extension. Ki Yung __**_ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe __**_ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://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] createProcess fails to find executable in Windows
Hi all, Consider the following program: module Test where import System.Process (readProcess) main :: IO () main = readProcess git [describe, --tags] = putStr In Windows I get the following behaviour: git --version git version 1.7.10.msysgit.1 ghc --version The Glorious Glasgow Haskell Compilation System, version 7.6.1 runghc Test Test: git: createProcess: does not exist (No such file or directory) The same happens with GHC 7.4.2. In Linux, however, it works as expected: $ git --version git version 1.7.9.5 $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.4.1 $ runghc Test.hs Package-2.0-68-gacaf77a Can anyone reproduce this result in Windows? Is this a bug or am I doing something wrong? Thanks, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] createProcess fails to find executable in Windows
On Thu, Oct 25, 2012 at 12:10 PM, Jesse Schalken m...@jesseschalken.comwrote: What if you ran the program from within the directory that contains git.exe? That seems to work. Can you check that the PATH environment variable is set correctly from within the program? If I run `system echo %PATH%` it shows me the expected %PATH%, including the directory where the git binary lives. Thanks, Pedro On Thu, Oct 25, 2012 at 10:05 PM, José Pedro Magalhães j...@cs.uu.nlwrote: Hi all, Consider the following program: module Test where import System.Process (readProcess) main :: IO () main = readProcess git [describe, --tags] = putStr In Windows I get the following behaviour: git --version git version 1.7.10.msysgit.1 ghc --version The Glorious Glasgow Haskell Compilation System, version 7.6.1 runghc Test Test: git: createProcess: does not exist (No such file or directory) The same happens with GHC 7.4.2. In Linux, however, it works as expected: $ git --version git version 1.7.9.5 $ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.4.1 $ runghc Test.hs Package-2.0-68-gacaf77a Can anyone reproduce this result in Windows? Is this a bug or am I doing something wrong? Thanks, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type-directed functions with data kinds
Hi Paul, On Thu, Oct 25, 2012 at 4:22 PM, Paul Visschers m...@paulvisschers.netwrote: Hello everyone, I've been playing around with the data kinds extension to implement vectors that have a known length at compile time. Some simple code to illustrate: {-# LANGUAGE DataKinds, GADTs, KindSignatures #-} import Prelude hiding (repeat) data Nat = Zero | Succ Nat data Vector (n :: Nat) a where Nil :: Vector Zero a Cons :: a - Vector n a - Vector (Succ n) a class VectorRepeat (n :: Nat) where repeat :: a - Vector n a instance VectorRepeat Zero where repeat _ = Nil instance VectorRepeat n = VectorRepeat (Succ n) where repeat x = Cons x (repeat x) In this code I have defined a repeat function that works in a similar way to the one in the prelude, except that the length of the resulting vector is determined by the type of the result. I would have hoped that its type would become 'repeat :: a - Vector n a', yet it is 'repeat :: VectorRepeat n = a - Vector n a'. As far as I can tell, this class constraint should no longer be necessary, as all possible values for 'n' are an instance of this class. I actually really just want to define a closed type-directed function and would rather not (ab)use the type class system at all. Is there a way to write the repeat function so that it has the type 'repeat :: a - Vector n a' that I've missed? If not, is this just because it isn't implemented or are there conceptual caveats? There are conceptual caveats; see http://hackage.haskell.org/trac/ghc/ticket/6074 (particularly the comments). This would require fundamentally changing the way in which constraints are elaborated into core code. Cheers, Pedro Paul Visschers ___ 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] Transforming a ADT to a GADT
Hi Florian, Will this do? class Tc a where tc :: Exp - Maybe (Term a) instance Tc Int where tc (Lit i) = return (TLit i) tc (Succ i) = tc i = return . TSucc tc (IsZero i) = Nothing tc e= tcIf e instance Tc Bool where tc (Lit i) = Nothing tc (Succ i) = Nothing tc (IsZero i) = tc i = return . TIsZero tc e= tcIf e tcIf :: (Tc a) = Exp - Maybe (Term a) tcIf (If c e1 e2) = do c' - tc c e1' - tc e1 e2' - tc e2 return (TIf c' e1' e2') Cheers, Pedro On Fri, Sep 14, 2012 at 11:45 AM, Florian Lorenzen florian.loren...@tu-berlin.de wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello cafe, I have a question wrt. to GADTs and type families in GHC (7.6.1). I'd like to transform a value of an ADT to a GADT. Suppose I have the simple expression language data Exp = Lit Int | Succ Exp | IsZero Exp | If Exp Exp Exp and the GADT data Term t where TLit :: Int - Term Int TSucc :: Term Int - Term Int TIsZero :: Term Int - Term Bool TIf :: Term Bool - Term ty - Term ty - Term ty that encodes the typing rules. Now, I'd like to have a function typecheck :: Exp - Maybe (Term t) typecheck exp = ... that returns the GADT value corresponding to `exp' if `exp' is type correct. I found a solution at http://okmij.org/ftp/tagless-final/TypecheckedDSLTH.hs but this has as type (slightly adapted) typecheck :: Exp - Maybe TypedTerm with data TypedTerm = forall ty. (Typ ty) (Term ty) data Typ ty = TInt Int | TBool Bool That is, the GADT value is hidden inside the existential and cannot be unpacked. Therefore, I cannot write a type preserving transformation function like transform :: Term t - Term t that gets the result of the `typecheck' function as input. The solution mentioned above uses Template Haskell to extract the `Term t' type from the existential package and argues that type errors cannot occur during splicing. Is there a possibility to avoid the existential and hence Template Haskell? Of course, the result type of typecheck depends on the type and type correctness of its input. My idea was to express this dependency by parameterizing `Exp' and using a type family `ExpType' like: typecheck :: Exp e - Maybe (Term (ExpType e)) typecheck (ELit i) = Just (TLit i) typecheck (ESucc exp1) = case typecheck exp1 of Nothing - Nothing Just t - Just (TSucc t) ... with data TEXP = L | S TEXP | IZ TEXP | I TEXP TEXP TEXP -- datakind data Exp (e::TEXP) where ELit :: Int - Exp L ESucc :: Exp e1 - Exp (S e1) EIsZero :: Exp e1 - Exp (IZ e1) EIf :: Exp e1 - Exp e2 - Exp e3 - Exp (I e1 e2 e3) It seems to me that `ExpType' then would be a reification of the type checker for `Exp' at the type level. But I did not know how to define it. Does it make sense at all? Is it possible in GHC? All the examples on the net I looked at either start with the GADT right away or use Template Haskell at some point. So, perhaps this `typecheck' function is not possible to write in GHC Haskell. I very much appreciate any hints and explanations on this. Best regards, Florian - -- Florian Lorenzen Technische Universität Berlin Fakultät IV - Elektrotechnik und Informatik Übersetzerbau und Programmiersprachen Sekr. TEL12-2, Ernst-Reuter-Platz 7, D-10587 Berlin Tel.: +49 (30) 314-24618 E-Mail: florian.loren...@tu-berlin.de WWW:http://www.user.tu-berlin.de/florenz/ -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlBTCr8ACgkQvjzICpVvX7ZfTgCeOPflPtaEW/w1McjYWheaRaqq oUQAnRXSrGP3se+3oiI3nnd+B/rK8yx8 =X1hR -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] explicit annotations on kind polymorphism for data types
Nope, but it should work on 7.6 (also on the release candidate). The 'X' should be lowercase, though, like type variables. Cheers, Pedro On Wed, Aug 22, 2012 at 12:01 AM, dude d...@methodeutic.com wrote: Hello All: I'm working through Giving Haskell a Promotion. Section 2.4 presents an explicitly annotated data type declaration similar to the following: data EqRefl (a::X)(b::X) where Refl :: forall X. forall (a::X). EqRefl a a Has this been implemented in GHC 7.4.2? 7.8.3 in the GHC User Guide leads me to believe it has not. -- dude __**_ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://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] [Haskell] [ANN] GenCheck - a generalized property-based testing framework
On Tue, Jun 19, 2012 at 4:04 PM, Jacques Carette care...@mcmaster.cawrote: User beware: this is gencheck-0.1, there are still a few rough edges. We plan to add a Template Haskell feature to this which should make deriving enumerators automatic for version 0.2. Can you provide me a quick pointer into what methods need to be generated automatically? Thanks, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] class instances for kinds with finite ty constrs, does this make sense?
Hi, This has been discussed before: http://haskell.1045720.n5.nabble.com/Data-Kinds-and-superfluous-in-my-opinion-constraints-contexts-td5689436.html Feel free to open a feature request for this. I think it's something we should consider addressing, but at the moment it's not immediately clear how to do it. Cheers, Pedro On Thu, Jun 7, 2012 at 7:32 PM, ex falso 0sle...@gmail.com wrote: Hi, i've been using DataKinds for a while and there seems to be a recurring annoyance that could be possibly eliminated with a language extension. It goes something like this: data Tuple (l :: [*]) where Unit :: Tuple '[] Comma :: a - Tuple as - Tuple (a ': as) data Proxy k = Proxy class TupleLength (l :: [*]) where tupleLength :: Proxy l - Integer instance TupleLength '[] where tupleLength _ = 0 instance (TupleLength as) = TupleLength '(a : as) where tupleLength _ = 1 + tupleLength (Proxy :: Proxy as) so far so good. but now if we want to use TupleLength: printLength :: (TupleLength l) = Tuple l - IO () printLength t = print $ tupleLength t we always have to put the class restriction (TupleLength l) there, even though all possible type constructors of [*] have a TupleLength instance defined! If we had a way to signal that all ty constrs are catered for then the compiler could check this, and deduce that l::[*] is always an instance. Well that's the hypothesis. Of course this would only make sense for kinds with finite no. of ty constructors, namely DataKinds-lifted types. Does this make sense? ex ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Bug in SYB, SYB-documentation or GHC-API (or I messed up somewhere)
Hi Philip, On Fri, May 11, 2012 at 5:12 PM, Philip K. F. Hölzenspies p...@st-andrews.ac.uk wrote: However, it turns out that this never leads to an evaluation of extTyNamesLoc. I've come as far as to see that, since Located a is a synonym for GenLocated SrcSpan a, the type we're looking for really has a binary constructor, thus we should use ext2Q. This made things work: We first modify the function we apply to Located things: extTyNamesLoc :: (Data loc, Data a) = SrcSpan - GenLocated loc a - OccurrenceTable extTyNamesLoc l (L l' x) = case cast l' of Just l'' - extTyNames l'' x Nothing - extTyNames l x Do you really need this? Can't you use the definition of `extTyNamesLoc` shown previously, and redefine `extTyNames` to use `ext2Q`, as in: extTyNames l x = (extTyNamesDef l x `mkQ` extTyNamesTy l `ext2Q` extTyNamesLoc l) x ? Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Annotaing abstract syntax trees
Hi Romildo, I had a quick look at your code. In general it seems fine, although I haven't tested it. You might want to use HLint to give you coding tips. I don't understand your remark about wanting the type checker to produce an expression annotated with both positions and calculated types. Can't you make `exprTypeCheck` operate on `Ann (Range, ExprType) ExprF` instead of just `Ann ExprType ExprF`? Cheers, Pedro [1] http://community.haskell.org/~ndm/hlint/ On Tue, May 8, 2012 at 3:05 PM, José Romildo Malaquias j.romi...@gmail.comwrote: Hello. I am reading Martijn's MSc Thesis Generic Selections of Subexpressions, where one can found some discussions about annotating abstract syntax trees (AST). In order to follow the discussion I wrote the attached Haskell program, which is an interpreter for an simple typed expression language. The Annotations package is used. The expression pattern is represented by a single recursive data type. Annotations are used for positions in the input source, and also for the type of expressions and subexpressions. I would like somebody to review the code and comment on it, as I am not sure I am using the concepts right. Also I would like the type checker to produce an expression annotated with both positions and calculated types. Currently it discards the position annotations. Any sugestions on how to modify it is welcome. Next step is adding a new form of expression to introduce local variable bindings. After that I want to start working with ASTs represented by mutually recursive data types. Then I will need multirec... Romildo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Annotations in abstract syntax tree
Hi Romildo, If I understand correctly, you now want to add annotations to mutually-recursive datatypes. The annotations package supports that. Section 8 of our paper [1] gives an example of how to do that, and also Chapter 6 of Martijn's MSc thesis [2]. Let me know if these references do not answer your question. Cheers, Pedro [1] http://www.dreixel.net/research/pdf/gss.pdf [2] http://martijn.van.steenbergen.nl/projects/Selections.pdf On Thu, Apr 26, 2012 at 10:07, j.romi...@gmail.com wrote: Hello. I need to annotate abstract syntax tree with additional information in a compiler. Using the Annotations package[1] I have written the following small program: import Annotations.F.Annotated import Annotations.F.Fixpoints data ExprF r = Num Double | Var String | Add r r | Sub r r | Mul r r | Div r r deriving (Eq,Show) type BareExpr = Fix ExprF e :: BareExpr e = In (Mul (In (Num 5)) (In (Add (In (Var x)) (In (Num 8) type ValExpr = Fix (Ann Double ExprF) type Memory = [(String,Double)] eval :: Memory - BareExpr - ValExpr eval _ (In (Num x)) = In (Ann x (Num x)) eval m (In (Var x)) = let y = case lookup x m of Just k - k Nothing - 0 in In (Ann y (Var x)) eval m (In (Add x y)) = op m (+) Add x y eval m (In (Sub x y)) = op m (-) Sub x y eval m (In (Mul x y)) = op m (*) Mul x y eval m (In (Div x y)) = op m (/) Div x y op m f k x y = let x'@(In (Ann v1 _)) = eval m x y'@(In (Ann v2 _)) = eval m y in In (Ann (f v1 v2) (k x' y')) With these definitions we can represent simple arithmetic expressions and we can also evaluate them, annotating each node in the abstract syntax tree with its corresponding value. Now I want to add statements to this toy language. One statement may be a print statement containing an expression whose value is to be printed, an assign statement containing an identifier and an expression, or a compound statement containing two statements to be executed in sequence. How the data types for statements can be defined? How a function to execute an statement anotating its node with the corresponding state (memory plus output) after its execution can be defined? Without annotations the type of statements could be: data Stm = PrintStm Expr | AssignStm String Expr | CompoundStm Stm Stm How to enable annotations in this case? Note that Stm uses both Expr and Stm. [1] http://hackage.haskell.org/package/Annotations Romildo ___ 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] Prettier pretty-printing of data types?
Hi, On Wed, Mar 14, 2012 at 07:54, Johan Holmquist holmi...@gmail.com wrote: I guess you want an automatically derived show that indents, but if you don't mind defining you own, Data.PrettyPrint is really nice. Though most likely any form of pretty-printing will be generic, and can be defined with GHC.Generics [1], for instance. Cheers, Pedro [1] http://www.haskell.org/haskellwiki/Generics ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Helper classes for Generics
Hi Reiner, It is indeed not strictly necessary to define such helper classes for kind * generic functions. You do need them for kind * - * functions, though. Also, I think they should always be used because they help keep things separate. If we use an implementation of generics with DataKinds [1], then the helper classes always have a different kind from the user-facing classes. Cheers, Pedro [1] http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/GenericDeriving#Kindpolymorphicoverhaul On Mon, Mar 12, 2012 at 04:27, Reiner Pope reiner.p...@gmail.com wrote: Hi all, I've been playing with GHC's new generics features (see http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-programming.html). All the documentation I've seen suggests creating a helper class -- for instance, the GSerialize class in the above link -- on which one defines generic instances. It seems to me that this isn't necessary. For example, here's the the example from the GHC docs, but without a helper class: -- set the phantom type of Rep to (), to avoid ambiguity from0 :: Generic a = a - Rep a () from0 = from data Bit = O | I class Serialize a where put :: a - [Bit] default put :: (Generic a, Serialize (Rep a ())) = a - [Bit] put = put . from0 instance Serialize (U1 x) where put U1 = [] instance (Serialize (a x), Serialize (b x)) = Serialize ((a :*: b) x) where put (x :*: y) = put x ++ put y instance (Serialize (a x), Serialize (b x)) = Serialize ((a :+: b) x) where put (L1 x) = O : put x put (R1 x) = I : put x instance (Serialize (a x)) = Serialize (M1 i c a x) where put (M1 x) = put x instance (Serialize a) = Serialize (K1 i a x) where put (K1 x) = put x Is there a reason to prefer using helper classes? Or perhaps we should update the wiki page (http://www.haskell.org/haskellwiki/Generics) to avoid using helper classes? Regards, Reiner ___ 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] Helper classes for Generics
Hi Yves, GHC.Generics [1] and SYB [2] are two rather different approaches to generic programming. There are things that can be done in one but not in the other, and there are things that are easier on one rather than the other. For instance, SYB tends to be very useful for large AST transformations, with functions that have a general behaviour but a couple of particular cases for a few constructors. GHC.Generics, on the other hand, can encode functions such as generic fmap and traverse. It lends itself better to optimisation since it doesn't use runtime casts, and as such tends to be faster than SYB. It isn't planned to replace SYB. Cheers, Pedro [1] http://www.haskell.org/haskellwiki/Generics [2] http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/SYB On Mon, Mar 12, 2012 at 16:35, Yves Parès yves.pa...@gmail.com wrote: I'd have a question concerning GHC.Generics: how does it relate to SYB's Data.Generics? Is it intended to replace it or complete it? In other words: does class Data.Generics.Data class do things that class GHC.Generics.Generic can't do? Le 12 mars 2012 04:27, Reiner Pope reiner.p...@gmail.com a écrit : Hi all, I've been playing with GHC's new generics features (see http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-programming.html). All the documentation I've seen suggests creating a helper class -- for instance, the GSerialize class in the above link -- on which one defines generic instances. It seems to me that this isn't necessary. For example, here's the the example from the GHC docs, but without a helper class: -- set the phantom type of Rep to (), to avoid ambiguity from0 :: Generic a = a - Rep a () from0 = from data Bit = O | I class Serialize a where put :: a - [Bit] default put :: (Generic a, Serialize (Rep a ())) = a - [Bit] put = put . from0 instance Serialize (U1 x) where put U1 = [] instance (Serialize (a x), Serialize (b x)) = Serialize ((a :*: b) x) where put (x :*: y) = put x ++ put y instance (Serialize (a x), Serialize (b x)) = Serialize ((a :+: b) x) where put (L1 x) = O : put x put (R1 x) = I : put x instance (Serialize (a x)) = Serialize (M1 i c a x) where put (M1 x) = put x instance (Serialize a) = Serialize (K1 i a x) where put (K1 x) = put x Is there a reason to prefer using helper classes? Or perhaps we should update the wiki page (http://www.haskell.org/haskellwiki/Generics) to avoid using helper classes? Regards, Reiner ___ 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] Helper classes for Generics
It could, yes. Actually, using DefaultSignatures you can probably use SYB for defining classes with generic default methods, by adding Data and Typeable constraints instead of Generic. Cheers, Pedro 2012/3/12 Yves Parès yves.pa...@gmail.com Thanks for the clarification. But could not class Data have been used for generic Deriving of classes? I imagine it would have been harder, but I fail to see if would have been possible... Le 12 mars 2012 16:58, José Pedro Magalhães j...@cs.uu.nl a écrit : Hi Yves, GHC.Generics [1] and SYB [2] are two rather different approaches to generic programming. There are things that can be done in one but not in the other, and there are things that are easier on one rather than the other. For instance, SYB tends to be very useful for large AST transformations, with functions that have a general behaviour but a couple of particular cases for a few constructors. GHC.Generics, on the other hand, can encode functions such as generic fmap and traverse. It lends itself better to optimisation since it doesn't use runtime casts, and as such tends to be faster than SYB. It isn't planned to replace SYB. Cheers, Pedro [1] http://www.haskell.org/haskellwiki/Generics [2] http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/SYB On Mon, Mar 12, 2012 at 16:35, Yves Parès yves.pa...@gmail.com wrote: I'd have a question concerning GHC.Generics: how does it relate to SYB's Data.Generics? Is it intended to replace it or complete it? In other words: does class Data.Generics.Data class do things that class GHC.Generics.Generic can't do? Le 12 mars 2012 04:27, Reiner Pope reiner.p...@gmail.com a écrit : Hi all, I've been playing with GHC's new generics features (see http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-programming.html). All the documentation I've seen suggests creating a helper class -- for instance, the GSerialize class in the above link -- on which one defines generic instances. It seems to me that this isn't necessary. For example, here's the the example from the GHC docs, but without a helper class: -- set the phantom type of Rep to (), to avoid ambiguity from0 :: Generic a = a - Rep a () from0 = from data Bit = O | I class Serialize a where put :: a - [Bit] default put :: (Generic a, Serialize (Rep a ())) = a - [Bit] put = put . from0 instance Serialize (U1 x) where put U1 = [] instance (Serialize (a x), Serialize (b x)) = Serialize ((a :*: b) x) where put (x :*: y) = put x ++ put y instance (Serialize (a x), Serialize (b x)) = Serialize ((a :+: b) x) where put (L1 x) = O : put x put (R1 x) = I : put x instance (Serialize (a x)) = Serialize (M1 i c a x) where put (M1 x) = put x instance (Serialize a) = Serialize (K1 i a x) where put (K1 x) = put x Is there a reason to prefer using helper classes? Or perhaps we should update the wiki page (http://www.haskell.org/haskellwiki/Generics) to avoid using helper classes? Regards, Reiner ___ 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] ANN: generic-deepseq 1.0.0.0
2012/2/25 Andres Löh andres.l...@googlemail.com Would you have an example of a type for which it would be useful to have a DeepSeq instance, and that would require a V1 instance? I cannot think of one now; I originaly thought it would be necessary to permit deriving DeepSeq instances for types tagged with void types, but as José explained, in that case, the V1 instance isn't needed because those void types don't show up in the representation. While void datatypes are rare, it just doesn't make sense to exclude them. It's an arbitrary restriction. Here's a constructed example: data X a = C1 Int | C2 a data Z -- empty type Example = X Z We're using Z as a parameter to X in order to exclude the use of the C2 case. Without a V1 case, you cannot use deepSeq on values of type Example. Yes, I agree. There should be a V1 instance, and it should return `undefined`. This gives the expected behavior of `seq` on an empty datatype, I think. If there is no V1 instance, you'll get a type-checking error (no instance for V1), preventing generic deepseq on any datatype that happens to use an empty datatype in its definition. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: generic-deepseq 1.0.0.0
2012/2/24 Maxime Henrion mhenr...@gmail.com On Fri, 2012-02-24 at 07:49 +0100, Jos Pedro Magalhes wrote: Hi, 2012/2/23 Maxime Henrion mhenr...@gmail.com * Why do you have the instance: instance GDeepSeq V1 where grnf _ = () The only way to construct values of a void type is using ⊥. And I would expect that rnf ⊥ = ⊥, not (). I think the best thing is to just remove the V1 instance. This would have the consequence that any type tagged with a phantom type (for whatever reason) couldn't be used with deepseq, it would return bottom. What if I want to deepseq a 2-3 finger tree tagged with a type-level natural that ensures the proper shape of the tree statically? It seemed to me that I should be able to do that; this is why I added this V1 instance. I'm not sure I understand your comment... V1 should only be used for datatypes without constructors, such as `data Empty`. Yes, such as the usual type-level naturals (not using DataKinds): data Z data S n Those can be used to tag a type which also contains actual values that you would want to deepseq? For example, a length-type vector? But in those cases they are used as tags, not as values, and hence do not show up in the generic representation. So if all you want is to be able to deepseq a value of a type like data Proxy t = Proxy even if your value is of type `Proxy Ze`, you shouldn't need a `V1` instance. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: generic-deepseq 1.0.0.0
Hi Andres, 2012/2/24 Andres Löh andres.l...@googlemail.com I don't understand what's going on here. Instances for V1 should of course be defined if they can be! And in this case, a V1 instance makes sense and should be defined. The definition itself doesn't matter, as it'll never be executed. The definition certainly matters: data Ze deriving Generic class DeepSeq a where rnf :: a - () default rnf :: (Generic a, GDeepSeq (Rep a)) = a - () rnf = grnf . from instance DeepSeq Ze class GDeepSeq f where grnf :: f a - () instance GDeepSeq V1 where grnf _ = () instance GDeepSeq a = GDeepSeq (M1 i c a) where grnf = grnf . unM1 -- other instances are not relevant now t :: Ze t = undefined seq t () == undefined. rnf t == (), because the V1 instance dictates so. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: generic-deepseq 1.0.0.0
Hi, 2012/2/23 Maxime Henrion mhenr...@gmail.com * Why do you have the instance: instance GDeepSeq V1 where grnf _ = () The only way to construct values of a void type is using ⊥. And I would expect that rnf ⊥ = ⊥, not (). I think the best thing is to just remove the V1 instance. This would have the consequence that any type tagged with a phantom type (for whatever reason) couldn't be used with deepseq, it would return bottom. What if I want to deepseq a 2-3 finger tree tagged with a type-level natural that ensures the proper shape of the tree statically? It seemed to me that I should be able to do that; this is why I added this V1 instance. I'm not sure I understand your comment... V1 should only be used for datatypes without constructors, such as `data Empty`. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: generic-deepseq 1.0.0.0
Hi, 2012/2/19 Bas van Dijk v.dijk@gmail.com I do think it's better to integrate this into the deepseq package (and thus removing the default implementation of rnf). Otherwise we end up with two ways of evaluating values to normal form. I agree with this, and I guess many people are already using the deepseq package (simply because it was there first), so it would be better to integrate the generic code with that package. As for the backwards compatibility loss, it is indeed a pity that you are forced to choose between a generic default and a normal default, but I don't see any easy way to change that, and the current behaviour is simple and predictable. So I do not propose we change that. In this case I agree with Bas, and propose removing the normal default for `rnf`. One last issue: Say I have a type like: data T = C !Int Currently GHC Generics can't express the strictness annotation. This means that your deepseq will unnecessarily evaluate the Int (since it will always be evaluated already). It would be nice if the strictness information could be added to the K1 type. (José, would it be hard to add this to GHC.Generics?) I don't think so; I think the right place to put it is as a method of the Selector class, though. But, I'm wondering, for your example, wouldn't/couldn't GHC optimize away `seq` calls to strict arguments? Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] GHC 7.4: Expected behavior or bug?
Hi, This is a change in behavior. Previously GHC was more liberal than Haskell 98 prescribed, and would not default the kind of otherwise unconstrained type variables to *. 7.4 does default to *, so you have to provide kind signatures when you want another kind (particularly in phantom type variables). Cheers, Pedro On Tue, Dec 27, 2011 at 16:47, Bas van Dijk v.dijk@gmail.com wrote: On 27 December 2011 17:38, Michael Snoyman mich...@snoyman.com wrote: Thanks to Mark Wright for pointing this out[1]. We have the equivalent of the following code in persistent: {-# LANGUAGE MultiParamTypeClasses #-} data Key backend entity = Key class Monad (b m) = Foo b m where func :: b m (Key b m) This code works fine with GHC 7.0, but I get the following message from GHC 7.4: Expecting two more arguments to `b' In the type `b m (Key b m)' In the class declaration for `Foo' Is this expected behavior, or a bug? If the former, what would be a possible workaround? Thanks, Michael [1] https://github.com/yesodweb/persistent/issues/31 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe I fixed a similar breakage in the hmatrix library: https://github.com/AlbertoRuiz/hmatrix/commit/a4f38eb196209436f72b938f6355f6e28474bef3 I don't know if it's a bug in GHC, but the workaround is to add an explicit kind signature: {-# LANGUAGE KindSignatures, MultiParamTypeClasses #-} data Key (backend :: * - * - *) entity = Key class Monad (b m) = Foo b m where func :: b m (Key b m) Cheers, Bas ___ 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] Poll: Do you want a mascot?
Yes On Wed, Nov 23, 2011 at 19:11, heathmatlock heathmatl...@gmail.com wrote: Question: Do you want a mascot? Answers: Yes No -- This is an attempt to figure out if this idea is going anywhere. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] A Mascot
In general, I like the idea of having a mascot, and think that something along these lines will be great. Cheers, Pedro On Wed, Nov 16, 2011 at 01:01, heathmatlock heathmatl...@gmail.com wrote: I liked Go's mascot, and I figure it couldn't hurt to have our own. I spent the past hour making this: http://i.imgur.com/Mib6Q.png What do you think? -- Heath Matlock +1 256 274 4225 ___ 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] Usage question with TemplateHaskell and Generic
Hi, I'm not sure I understand your question. But if you mean that you want to retrieve the type variable names, as they were defined in the source, then I can tell you that the generic deriving mechanism cannot do this. Cheers, Pedro On Sun, Nov 6, 2011 at 14:35, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: Hi, I'd like to simpler the work of deriving MyClass. And I have two ways to do: TemplateHaskell $(derivingMyClass), or Generic deriving (MyClass). Since I need to get the type name in the deriving, then I met this question: If I have data A b = C b, then with TemplateHaskell, the type would be VarT b, which means at compile time, I cannot get the exact type, so the type name would be b. So I wonder if this could be resolved by TemplateHaskell, or Generic is the only choice. PS: I have not tried to do this in Generic. -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is generic information dumpable?
Hi, Now, for the following datatype: data X a = X { myX :: a } deriving Generic You get the following -ddump-deriv output: Derived instances Derived instances: instance GHC.Generics.Generic (Temp.X a_adY) where GHC.Generics.from (Temp.X g1_aeG) = GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.K1 g1_aeG))) GHC.Generics.to (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.K1 g1_aeH = Temp.X g1_aeH instance GHC.Generics.Datatype Temp.D1X where GHC.Generics.datatypeName _ = X GHC.Generics.moduleName _ = Temp instance GHC.Generics.Constructor Temp.C1_0X where GHC.Generics.conName _ = X GHC.Generics.conIsRecord _ = GHC.Types.True instance GHC.Generics.Selector Temp.S1_0_0X where GHC.Generics.selName _ = myX Generic representation: Generated datatypes for meta-information: Temp.D1X Temp.C1_0X Temp.S1_0_0X Representation types: Temp.Rep_X = GHC.Generics.D1 Temp.D1X (GHC.Generics.C1 Temp.C1_0X (GHC.Generics.S1 Temp.S1_0_0X (GHC.Generics.Par0 a_adY))) Still not perfect, in that the representation type should really appear as a type instance inside the Generic instance, but at least all the important information is printed. Cheers, Pedro 2011/11/3 Bas van Dijk v.dijk@gmail.com 2011/11/3 José Pedro Magalhães j...@cs.uu.nl: -ddump-deriv will print (most of) it. But it doesn't print the most useful piece of information: the definition of Rep. It would be great if this could be added. Currently when I have a type that I want to know the Rep of, say: data Foo = Bar Int | Boo {hello :: String} deriving Generic I just convert it to a Rep and show it: err = show $ from $ Boo World However Reps don't have Show instances so GHC complains: No instance for (Show (D1 D1Foo ( C1 C1_0Foo (S1 NoSelector (Rec0 Int)) :+: C1 C1_1Foo (S1 S1_1_0Foo (Rec0 String)) ) x0 ) ) arising from a use of `show' And there you go. This is the only time when I'm happy to see an error message :-) Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is generic information dumpable?
2011/11/4 Bas van Dijk v.dijk@gmail.com Thanks José! Will this make it into ghc-7.4? Yes, I think so. Cheers, Pedro Bas 2011/11/4 José Pedro Magalhães j...@cs.uu.nl: Hi, Now, for the following datatype: data X a = X { myX :: a } deriving Generic You get the following -ddump-deriv output: Derived instances Derived instances: instance GHC.Generics.Generic (Temp.X a_adY) where GHC.Generics.from (Temp.X g1_aeG) = GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.K1 g1_aeG))) GHC.Generics.to (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.M1 (GHC.Generics.K1 g1_aeH = Temp.X g1_aeH instance GHC.Generics.Datatype Temp.D1X where GHC.Generics.datatypeName _ = X GHC.Generics.moduleName _ = Temp instance GHC.Generics.Constructor Temp.C1_0X where GHC.Generics.conName _ = X GHC.Generics.conIsRecord _ = GHC.Types.True instance GHC.Generics.Selector Temp.S1_0_0X where GHC.Generics.selName _ = myX Generic representation: Generated datatypes for meta-information: Temp.D1X Temp.C1_0X Temp.S1_0_0X Representation types: Temp.Rep_X = GHC.Generics.D1 Temp.D1X (GHC.Generics.C1 Temp.C1_0X (GHC.Generics.S1 Temp.S1_0_0X (GHC.Generics.Par0 a_adY))) Still not perfect, in that the representation type should really appear as a type instance inside the Generic instance, but at least all the important information is printed. Cheers, Pedro 2011/11/3 Bas van Dijk v.dijk@gmail.com 2011/11/3 José Pedro Magalhães j...@cs.uu.nl: -ddump-deriv will print (most of) it. But it doesn't print the most useful piece of information: the definition of Rep. It would be great if this could be added. Currently when I have a type that I want to know the Rep of, say: data Foo = Bar Int | Boo {hello :: String} deriving Generic I just convert it to a Rep and show it: err = show $ from $ Boo World However Reps don't have Show instances so GHC complains: No instance for (Show (D1 D1Foo ( C1 C1_0Foo (S1 NoSelector (Rec0 Int)) :+: C1 C1_1Foo (S1 S1_1_0Foo (Rec0 String)) ) x0 ) ) arising from a use of `show' And there you go. This is the only time when I'm happy to see an error message :-) Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc 7.2.1 Generics problem
Thanks, you spotted another mistake on that page, I corrected it. Make sure to have a look at the functions in http://hackage.haskell.org/package/generic-deriving too; I'm sure those compile :-) Pedro 2011/11/3 Magicloud Magiclouds magicloud.magiclo...@gmail.com 2011/11/1 José Pedro Magalhães j...@cs.uu.nl: Oh, right, I see that some things on that page need updating; I'll do so. Thanks, Pedro On Tue, Nov 1, 2011 at 09:33, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: On Tue, Nov 1, 2011 at 1:59 PM, Andres Löh andres.l...@googlemail.com wrote: Hi. I do not know why, my ghc 7.2.1 does not seem to support DeriveRepresentable. I compiled the ghc 7.2.1 myself by ghc 7.0.4. All options default. $ ghc Types/TopTalkerRecord.hs Types/TopTalkerRecord.hs:2:14: Unsupported extension: DeriveRepresentable There's no extension of that name in 7.2.1. Do you mean DeriveGeneric? Cheers, Andres I do not know. I will try that. I got the name from http://www.haskell.org/haskellwiki/Generics. -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Thank you. I saw the page was updated. So I followed the document. And got stuck again. Copying the code and compile, I got: 25instance (GSerialize a) = GSerialize (M1 i a) where 26 gput (M1 x) = gput x test.hs:25:40: `M1 i a' is not applied to enough type arguments The first argument of `GSerialize' should have kind `* - *', but `M1 i a' has kind `(* - *) - * - *' In the instance declaration for `GSerialize (M1 i a)' -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to speedup generically parsing sum types?
Hi Bas, First of all, thanks for these numbers. I have previously compared the performance of GP libs [1] and your results confirm what I would expect, except for that last one, BigSum/fromJSON/generic. It's good that you're using INLINE pragmas on the generic function already. What I would also try: - Compile with -O2 and -fno-spec-constr-count (this last one is particularly important) - Add {-# INLINE [1] #-} pragmas to the to/from methods of your Generic instances. To add these INLINE pragmas you will have to give your own instances of Generic (so you can't derive them). I'd suggest you get hold of them with -ddump-deriv, copy-paste and add the pragmas, just for testing purposes. The phase is important: you first want to make sure you inline the generic function definition, and only then the from/to. Please keep me posted on the effects of these suggestions. In particular, if the INLINE pragmas on the from/to methods are essential, I'll be happy to add them to the derived instances. Cheers, Pedro [1] http://dreixel.net/research/pdf/ogie.pdf 2011/11/3 Bas van Dijk v.dijk@gmail.com Hello, I recently added default generic implementations of toJSON and parseJSON to the aeson package. Now I'm optimizing them. Here are some benchmark results that compare: * th: toJSON and fromJSON generated by template-haskell. Can be compared to hand-written code. Should be the fastest of all. * syb: toJSON and fromJSON from the Data.Aeson.Generic module. Uses the Data type class. * generic: my toJSON and fromJSON using GHC Generics. The benchmark itself can be found here: https://github.com/basvandijk/aeson/blob/optimizations/benchmarks/AesonCompareAutoInstances.hs toJSON == D/toJSON/th 3.631734 us D/toJSON/syb32.66679 us D/toJSON/generic3.371868 us BigRecord/toJSON/th 8.982990 us BigRecord/toJSON/syb48.90737 us BigRecord/toJSON/generic8.971597 us BigProduct/toJSON/th1.578259 us BigProduct/toJSON/syb 29.21153 us BigProduct/toJSON/generic 1.623115 us BigSum/toJSON/th51.81214 ns BigSum/toJSON/syb 1.256708 us BigSum/toJSON/generic 71.32851 ns fromJSON D/fromJSON/th 7.017204 us D/fromJSON/syb 23.46567 us D/fromJSON/generic 7.968974 us BigRecord/fromJSON/th 8.513789 us BigRecord/fromJSON/syb 36.64501 us BigRecord/fromJSON/generic 10.07809 us BigProduct/fromJSON/th 2.430677 us BigProduct/fromJSON/syb 17.97764 us BigProduct/fromJSON/generic 2.201130 us BigSum/fromJSON/th 414.8699 ns BigSum/fromJSON/syb 4.113170 us BigSum/fromJSON/generic 13.62614 us !!! As can be seen, in most cases the GHC Generics implementation is much faster than SYB and just as fast as TH. I'm impressed by how well GHC optimizes the code! Unfortunately the last benchmark, generically parsing a big sum type, is much slower. The code for parsing sums, which can be found here: https://github.com/basvandijk/aeson/blob/optimizations/Data/Aeson/Types/Internal.hs#L1059 is basically this: instance (GFromSum a, GFromSum b) = GFromJSON (a :+: b) where gParseJSON (Object (M.toList - [keyVal])) = gParseSum keyVal gParseJSON v = typeMismatch sum (:+:) v {-# INLINE gParseJSON #-} class GFromSum f where gParseSum :: Pair - Parser (f a) instance (GFromSum a, GFromSum b) = GFromSum (a :+: b) where gParseSum keyVal = (L1 $ gParseSum keyVal) | (R1 $ gParseSum keyVal) {-# INLINE gParseSum #-} instance (Constructor c, GFromJSON a, ConsFromJSON a) = GFromSum (C1 c a) where gParseSum (key, value) | key == pack (conName (undefined :: t c a p)) = gParseJSON value | otherwise = notFound $ unpack key {-# INLINE gParseSum #-} notFound :: String - Parser a notFound key = fail $ The key \ ++ key ++ \ was not found {-# INLINE notFound #-} Any idea how to make it faster? Regards, Bas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is generic information dumpable?
-ddump-deriv will print (most of) it. Cheers, Pedro On Thu, Nov 3, 2011 at 16:26, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: Hi, I am learning the new generic feature of ghc. I'd have to say, it is harder than template to enter. When I started to learn template, ghc -ddump-slices really helped. So I wonder if I could get the representation generated when deriving Generic. I think that would be a great help. -- 竹密岂妨流水过 山高哪阻野云飞 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Is generic information dumpable?
Hi, 2011/11/3 Bas van Dijk v.dijk@gmail.com 2011/11/3 José Pedro Magalhães j...@cs.uu.nl: -ddump-deriv will print (most of) it. But it doesn't print the most useful piece of information: the definition of Rep. Yes... I am aware of this. It would be great if this could be added. I'll do it. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ghc 7.2.1 Generics problem
Oh, right, I see that some things on that page need updating; I'll do so. Thanks, Pedro On Tue, Nov 1, 2011 at 09:33, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: On Tue, Nov 1, 2011 at 1:59 PM, Andres Löh andres.l...@googlemail.com wrote: Hi. I do not know why, my ghc 7.2.1 does not seem to support DeriveRepresentable. I compiled the ghc 7.2.1 myself by ghc 7.0.4. All options default. $ ghc Types/TopTalkerRecord.hs Types/TopTalkerRecord.hs:2:14: Unsupported extension: DeriveRepresentable There's no extension of that name in 7.2.1. Do you mean DeriveGeneric? Cheers, Andres I do not know. I will try that. I got the name from http://www.haskell.org/haskellwiki/Generics. -- 竹密岂妨流水过 山高哪阻野云飞 ___ 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] Hackage feature request: E-mail author when a package breaks
On Tue, Nov 1, 2011 at 09:43, Conrad Parker con...@metadecks.org wrote: On 1 November 2011 03:43, Alexander Kjeldaas alexander.kjeld...@gmail.com wrote: On 31 October 2011 17:22, Yitzchak Gale g...@sefer.org wrote: Gregory Crosswhite wrote: could [Hackage] have a feature where when a working package breaks with a new version of GHC the author is automatically e-mailed? This would be nice. However, there would have to be a way for it to be turned on and off by the author. (Spam is not nice.) How about sending an email to haskell-package-packate-name@haskell.org , and then people can join that mailing list if they are interested in that sort of stuff? Mailman is good at doing subscribe and unsubscribe. +1 I like this because it is opt-in for the maintainer, and also allows anyone else who is interested in the package to track it. Per-package RSS updates of build failures would also be useful. +1 Pedro Conrad. ___ 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] lost in generics
Hi Rusi, GHC has built-in support for two generic programming libraries. SYB [1] support has been there for a long time. The new generic mechanism [2], which allows you to define your own, (almost) derivable classes, only appeared in 7.2, but is planned to stay. What library you should use depends on what you want to do. There's a (slightly outdated) paper about that [3]. If you're looking into AST manipulations, SYB (or Uniplate [4]) might be the best pick. For most things I prefer the new generic mechanism, though. Cheers, Pedro [1] http://www.cs.uu.nl/wiki/GenericProgramming/SYB [2] http://www.haskell.org/ghc/docs/latest/html/users_guide/generic-programming.html [3] http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.140.3330 [4] http://community.haskell.org/~ndm/uniplate/ On Thu, Oct 20, 2011 at 18:12, Rustom Mody rustompm...@gmail.com wrote: I need some help finding my way around the various generics libraries. My usage scenario is -- at least to start with -- the ASTs of programming languages. It appears to me that there are two generations of generics -- earlier there was generic haskell and strafunski Now there is uniplate and kure (and syb? -- not sure of its generation...) I get this impression because I saw a comment somewhat along these lines. And also the very first reference link on the strafunski webpage: http://www.haskell.org/haskellwiki/Applications_and_libraries/Generic_programming/Strafunski viz http://www.cs.vu.nl/Strafunski/ seems to be dead. So I am wondering whether strafunski is still under development or is it defunct? The following paras from http://www.cs.uu.nl/research/techreps/repo/CS-2008/2008-010.pdf The current status of generic programming in Haskell is comparable to the lazy Tower of Babel preceding the birth of Haskell in the eighties [Hudak et al., 2007]. We have many single-site languages or libraries, each individually lacking critical mass in terms of language/library-design effort, implementations, and users. Although generic programming has been used in several applications, it has few users for real-life projects. This is understandable. Developing a large application takes a couple of years, and choosing a particular approach to generic programming for such a project involves a risk. Few approaches that have been developed over the last decade are still supported, and there is a high risk that the chosen approach will not be supported anymore, or that it will change in a backwards-incompatible way in a couple of years time. sound omninous :-) In general my question is: What is alive/active and what is alive/active and what is -- um -- moved-on-from. And of course which are easier and which more difficult to dig into. Thanks Rusi ___ 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] DSL for data definition (e.g. compiling Haskell type defs into Google's protocol buffers type defs)
Hi Karel, You can use SYB's toConstr/dataTypeOf [1] to obtain information about the name of the constructor and datatype. Alternatively, you can also use the new generic programming framework of ghc-7.2 [2]. Cheers, Pedro [1] http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Data.html#v:toConstr [2] http://haskell.org/ghc/docs/latest/html/libraries/ghc-prim-0.2.0.0/GHC-Generics.html#t:Datatype On Tue, Oct 4, 2011 at 17:02, Karel Gardas karel.gar...@centrum.cz wrote: Hello, I'm trying to find out if it's possible to use Haskell data type definition capability to define types and compile defined types into other languages, for example into Google's protocol buffers data definition language. So basically speaking I'm thinking about using Haskell sub-set as a data-definition DSL together with some functions which will generate some code based on supplied defined data types. My idea is: data Person = Person { id :: Int , name :: String , email :: Maybe String } deriving (Show, Data, Typeable) emit_proto Person 1 where emit_proto is function which will translate Person data type definition into Google's proto language (the 1 is index from which start to index type's fields) by traversing data type definition and translating all its children plus do some header/footer generation etc: message Person { required int32 id = 1; required string name = 2; optional string email = 3; } I've looked for something like that and found SYB papers which works on top of data instance (i.e. actual data, not data type). I also found JSON lib which again works on top of data and not data type. I've tried to look into Data.Typetable etc, but have not found function which will print data type's field name and field type name (although JSON lib seems to use field name for JSON generation so I'll need to investigate this more). I've tested `typeOf' function and it's quite useful, but its limitation is that it's not working on ADT name: data Color = RED|GREEN|BLUE *Main typeOf Color interactive:1:8: Not in scope: data constructor `Color' *Main typeOf RED Main.Color and I would need that in order to translate Color defined above into enum like: enum Color { RED = 0; GREEN = 1; BLUE = 2; } My question is: do you think I'm looking into good direction (i.e. Data/Typeable) or do you think I'll need to use something different for data definition DSL (Template Haskell?, or impossible in Haskell so write my own language with full parser? etc?) Thanks for any idea or opinion on this! Karel __**_ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://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] Generics (SYB) with parametrized types
Hi, I'm not sure I fully understand what you're trying to do, but when I read Ideally, I'd like to restrict my search to Located instances that wrap an instance of Outputable, I think this means SYB is not the right tool. Due to the way Typeable works (it's monomorphic), SYB doesn't really play well with adhoc cases for types which satisfy given class constraints. Your adhoc cases have to be listed per type, a bit like in the empty function [1], for instance. Also, SYB and parametrized types don't really mix all that well either. This affects things like extracting all the `b`s from a `Located b`. Perhaps you could have a look at the new generics in GHC 7.2 [2]? You should be able to derive `Generic` for all the GHC API types (using standalone deriving), and this mechanism deals fine with (single) parametrized types. I'd be happy to hear what happens if you try this. Cheers, Pedro [1] http://hackage.haskell.org/packages/archive/syb/latest/doc/html/src/Data-Generics-Builders.html#empty [2] http://www.haskell.org/haskellwiki/Generics On Thu, Aug 11, 2011 at 17:56, JP Moresmau jpmores...@gmail.com wrote: Hello, I'm banging my head against a wall there trying to use the syb generics schemes against the GHC API. I'm looking at implementing a search mechanism in the AST in the more direct way that what Scion does (creating an instance of a TypeClass for each AST node type). Since the GHC AST types derive from Data and Typeable, I thought it would be possible. So the problem is a follows: I have a start type, say TypecheckedSource, that derives from Data. What I'd like to do is to find all instances of the Located type inside that source that span a particular range. The problem is that Located is a parametrized type that wraps anything and just add location information. So the result of the search could be anything. Ideally, I'd like to restrict my search to Located instances that wrap an instance of Outputable, pretty print that and output only the result. So I'm looking to implement something that would have that signature: TypecheckedSource - (Line,Column) - [String] I have written code along these lines: everything (++) ([] `mkQ` overlap) ts where overlap :: forall b1 . (Outputable b1, Typeable b1) =Located b1 - [String] overlap (a::Located b1)= ... trivial code here finding if the location overlaps, and if it does, pretty print the object, otherwise returns [] And GHC complains: Ambiguous type variable `b10' in the constraints: (Outputable b10) arising from a use of `overlap' at ... (Typeable b10) arising from a use of `overlap' at ... So it doesn't like the fact that I don't know which types my Located instances wrap. But that's the point, I don't care, I just want to restrict my search to the ones I can pretty print. If I just try the code against simple non parametrized types it of course works. If I add some forall b1 . (Outputable ... in my main function signature it complains that I never use b1 anywhere else in the signature, of course. Is there a way to achieve what I want (-XOhPleaseDoWhatIwantEvenIfIamNotSureItMakesSense or something)? Thanks a million! -- JP Moresmau http://jpmoresmau.blogspot.com/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Deriving instances with GADTs
Hi Tim, On Thu, Aug 4, 2011 at 08:57, Tim Cowlishaw t...@timcowlishaw.co.uk wrote: Hi all, I've been writing a DSL to describe securities orders, and after a lot of help from the kind folk of this list and #haskell have come up with the following implementation, using generalised algebraic data types: https://gist.github.com/1124621 Elsewhere in my application, I make use of the order type defined therein in the following newtype declaration: newtype OrderListLevel s = OrderListLevel {orders :: [Order s Limit]} deriving (Eq, Show) However, the 'deriving' clause here fails: src/Simulation/OrderList.hs:9:82: No instance for (Eq (Order s Limit)) arising from the 'deriving' clause of a data type declaration at src/Simulation/OrderList.hs:9:82-83 src/Simulation/OrderList.hs:9:86: No instance for (Show (Order s Limit)) arising from the 'deriving' clause of a data type declaration at src/Simulation/OrderList.hs:9:86-89 I don't fully understand this - the error is correct that there is no instance of either Eq or Show for (Order s Limit), however, instances are defined for Order Buy Limit and Order Sell Limit, and since these are the only possible types that a value can be constructed with (the type constructor is 'closed' over these types in some sense I guess), it seems to me that this should provide enough information to derive the Eq and Show instances. Am I making unreasonable expectations of ghci's instance-deriving mechanism here, or missing something obvious? Here you seem to be using newtype deriving in particular, which behaves differently from standard deriving. Compiling with -ddump-deriv will show you the instances GHC is generating, which can help in debugging. Note however that deriving instances for GADTs is not trivial, in general. In particular, you should not assume that GHC knows that `s` can only be instantiated with `Buy` and `Sell` since (because we lack a proper kind system) nothing prevents you from later using, say, `Order Int Limit` somewhere. I describe the issue in more detail in the paper: José Pedro Magalhães and Johan Jeuring. Generic Programming for Indexed Datatypes. Color pdf: http://dreixel.net/research/pdf/gpid.pdf Greyscale pdf: http://dreixel.net/research/pdf/gpid_nocolor.pdf Cheers, Pedro Many thanks in advance, Tim ___ 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] I confused myself with generics, and now I confused ghc too
Hi Ari, I won't really try to answer your question, but I'll give you the code for gzipWithQ written by Alexey Rodriguez Yakushev some years ago for his comparison on generic programming libraries. The original darcs repo no longer exists, but here is the file which I think is relevant for you: {-# OPTIONS_GHC -fglasgow-exts #-} {-# OPTIONS_GHC -fallow-undecidable-instances #-} {-# OPTIONS_GHC -fallow-overlapping-instances #-} module Traversals where import Data.Generics.SYB.WithClass.Basics import BinTreeDatatype import BinTreeReps These traversals were copied (and adapted) from CtxSchemes.hs. That file is distributed in http://homepages.cwi.nl/~ralf/syb3/code.html The adaptations are necessary so that it works with SYB3 distributed in: darcs get http://happs.org/HAppS/syb-with-class -- | A type constructor for accumulation newtype A a c d = A { unA :: a - (a, c d) } gfoldlAccum :: Data ctx d = Proxy ctx - (forall d r. Data ctx d = a - c (d - r) - d - (a, c r)) - (forall g. a - g - (a, c g)) - a - d - (a, c d) gfoldlAccum ctx k z a d = unA (gfoldl ctx k' z' d) a where k' c y = A (\a - let (a', c') = unA c a in k a' c' y) z' f = A (\a - z a f) -- | gmapQr with accumulation gmapAccumQr :: Data ctx d = Proxy ctx - (r' - r - r) - r - (forall d. Data ctx d = a - d - (a,r')) - a - d - (a, r) gmapAccumQr ctx o r f a d = let (a',l) = gfoldlAccum ctx k z a d in (a',unQr l r) where k a (Qr c) d = let (a',r') = f a d in (a', Qr (\r - c (r' `o` r))) z a _ = (a, Qr id) -- | gmapQ with accumulation gmapAccumQ :: Data ctx d = Proxy ctx - (forall d. Data ctx d = a - d - (a,q)) - a - d - (a, [q]) gmapAccumQ ctx f = gmapAccumQr ctx (:) [] f Adapted from the source code of SYB 12 to work with syb3 gzipWithQ :: forall ctx r . Proxy ctx - GenericQ ctx (GenericQ ctx r) - GenericQ ctx (GenericQ ctx [r]) gzipWithQ ctx f x y = case gmapAccumQ ctx perkid funs y of ([], r) - r _ - error gzipWithQ where perkid a d = (tail a, unGQ (head a) d) funs :: [GenericQ' ctx r] funs = gmapQ ctx (\k - GQ (f k)) x newtype GenericQ' ctx r = GQ { unGQ :: GenericQ ctx r } Adapted from CtxSchemes.hs everything :: Proxy ctx - (r - r - r) - GenericQ ctx r - GenericQ ctx r everything ctx k f x = foldl k (f x) (gmapQ ctx (everything ctx k f) x) everywhere :: Proxy ctx - GenericT ctx - GenericT ctx everywhere ctx f = f . gmapT ctx (everywhere ctx f) Let me know if this doesn't work, or if you need something else. Cheers, Pedro On Mon, Jul 18, 2011 at 15:42, Ari Rahikkala ari.rahikk...@gmail.comwrote: I want to implement generic comparison on top of syb-with-class, and based on looking at syb, it seems I could base it on something like gzipWithQ from syb's Data.Generics.Twins. However, there's no Data.Generics.SYB.WithClass.Twins. So I set out to see if I can write one myself (well, one with just enough stuff to support gzipWithQ anyway) Here's what I've got so far: http://hpaste.org/49168 The problem is that GHCi seems to be somewhat confused, or at least confusing, about the type of gzipWithQ here. When I ask with :t, it reports the type as: gzipWithQ :: (Data ctx a2, Data ctx a3, Data ctx a) = Proxy ctx - (forall a0. Data ctx a0 = a0 - forall a1. Data ctx a1 = a1 - r) - a2 - a3 - [r] If I actually replace gzipWithQ's annotated type with this, GHCi will reject the program. And in any case with GenericQ being defined as type GenericQ ctx r = Data ctx a = a - r, isn't this closer to gzipWithQ's type with the type synonyms expanded? gzipWithQ :: forall ctx a r. Data ctx a = Proxy ctx - (Data ctx a0 = a0 - (Data ctx a1 = a1 - r)) - (Data ctx a2 = a2 - (Data ctx a3 = a3 - [r])) (GHCi accepts this as gzipWithQ's type so I assume it's the same one. I assume those class constraints after the = come with implicit foralls? Because it seems to mean the same thing if I put foralls in there) I have no idea how to even start figuring out how to make gzipWithQ and its type work. I only got this far by copying code from Data.Generics.Twins and passing down the proxy parameter and/or context type parameter (is it even possible for this approach to work?). What I can tell is that GHCi will still change the type like that even if gzipWithQ = undefined, so I'll have to change the type and not just the body of the function. Is this the kind of thing that all those newtypes in Data.Generics.Twins are for? Should I read up on type theory? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org
[Haskell-cafe] Build failure on Hackage, missing syb
Hi all, What causes the following build failure on Hackage? *** setup configure Configuring instant-generics-0.3.2... cabal-setup: At least the following dependencies are missing: syb 0.4 This is in package instant-generics-0.3.2http://hackage.haskell.org/packages/archive/instant-generics/0.3.2/logs/failure/ghc-7.0. The syb package built fine on Hackage. Previously, packages depending on syb built fine too (e.g. http://hackage.haskell.org/package/syz). So why is instant-generics-0.3.2 not building? Thanks, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Local copy of hackageDB
Hi all, I want to use cabal-install on a machine without internet access. I tried downloading http://hackage.haskell.org/cgi-bin/hackage-scripts/archive.tar, unpacking it and setting the local-repo field in the config file to this location but that doesn't work, as cabal-install says that it is missing the package list for the local repo. What should I do? Thanks, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Local copy of hackageDB
Hi Yitz, Thanks, but I don't really need a functional server or anything; I just want to have a local copy of Hackage on disk (latest versions only will do) and tell cabal-install to use that instead of the web. Regarding yackage, I don't think I can open ports on that machine either... Thanks, Pedro 2011/4/7 Yitzchak Gale g...@sefer.org José Pedro Magalhães wrote: I want to use cabal-install on a machine without internet access. Work is ongoing for a version of hackage that you can just install on your own server. Perhaps the people working on that can comment about the status. If all you want is a barebones server that you can upload packages to for use via cabal-install, you can get: http://hackage.haskell.org/package/yackage Hope this helps, Yitz ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Local copy of hackageDB
Yes, I have that tarball. I just don't know how to tell cabal-install to use it. Going to each package, individually unpacking and installing it is what I've been doing so far, but I was hoping that could be automated. Cheers, Pedro On Thu, Apr 7, 2011 at 14:18, Magnus Therning mag...@therning.org wrote: On Thu, Apr 7, 2011 at 11:21, Marc Weber marco-owe...@gmx.de wrote: Local copy ? You know that hackage is hosting several thausands of source archives - also old versions you don't want? Do you want to mirror everything locally? Fetching latest versions only to generate hashes takes many hours. (Experience from hack-nix). There's a tar-ball served from http://hackage.haskell.org/packages/hackage.html (http://hackage.haskell.org/cgi-bin/hackage-scripts/archive.tar) which contains the latest version of all packages. I think that's what the OP is using. Downloading a 150MB tar-ball shouldn't take many hours, if you're on a decent connection. /M -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: mag...@therning.org jabber: mag...@therning.org twitter: magthe http://therning.org/magnus ___ 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] Install GTK on Windows
Thanks, that worked! First it was loading stuff from graphviz, and then from sysWOW64... now I finally run threadscope :-) Cheers, Pedro 2011/3/15 Ryan Yates fryguy...@gmail.com Hi Pedro, Perhaps the libglib-2.0.0.dll that is getting loaded is not the one you want. You should be able to use a tool like process explorer [1] to see which specific dlls are getting loaded when you run. Ryan [1] http://technet.microsoft.com/en-us/sysinternals/bb896653 2011/3/15 José Pedro Magalhães j...@cs.uu.nl Hi all, I'd just like to add that I succeeded in building gtk2hs in Windows XP 64bit with GHC 7.0.2, using the 2.16 bundle from [1] and following the instructions in [2]. However, running the test program of [2] still fails at runtime with The procedure entry point g_assertion_message_expr could not be located in the dynamic link library libglib-2.0.0.dll. Any idea what could cause this? Do I need to add -l something when compiling the program? Thanks, Pedro [1] http://www.gtk.org/download-windows.html [2] http://markshroyer.com/2010/10/gtk2hs-on-windows/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Install GTK on Windows
Hi all, I'd just like to add that I succeeded in building gtk2hs in Windows XP 64bit with GHC 7.0.2, using the 2.16 bundle from [1] and following the instructions in [2]. However, running the test program of [2] still fails at runtime with The procedure entry point g_assertion_message_expr could not be located in the dynamic link library libglib-2.0.0.dll. Any idea what could cause this? Do I need to add -l something when compiling the program? Thanks, Pedro [1] http://www.gtk.org/download-windows.html [2] http://markshroyer.com/2010/10/gtk2hs-on-windows/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Some quick experiments with GHC 7.0.2 in Intel's Manycore Testing Lab (32 cores)
Hi all, I've played a bit with Intel's Manycore Testing Lab ( http://software.intel.com/en-us/articles/intel-many-core-testing-lab/). Part of the agreement to use it requires that you report back your experiences, which I did in an Intel forum post ( http://software.intel.com/en-us/forums/showthread.php?t=81396). I thought this could be interesting to the Haskell community in general as well, so I'm reposting here, and pasting the text below for convenience. I've replaced the images with links. Cheers, Pedro As per the agreement with Intel, I am reporting my experiences with the Intel Manycore Testing Lab (Linux). This was my first time in the lab, and I wanted to test GHC's [1] SMP parallelism [2] features. The first challenge was to actually get GHC to work on the lab. There was a working version of ghc under /opt/ghc6.13/bin/ghc, but I really needed GHC 7. So first I built GHC 7.0.2-rc2, which worked without much trouble. Next step was to get all the necessary libraries in place. Since the lab has no direct internet access, cabal-install [3] wouldn't be of much use. Instead, I downloaded a snapshot of hackage [4] with the latest version of every package and manually installed the packages I needed. A bit boring, but doable. Finally I was ready to compile my programs and test. First thing I tried was an existing algorithm I had which, at some point, takes a list of about 500 trees and, for each tree, computes a measure which is expressed as a floating point number. This is basically a map over a list transforming each tree into a float. Each operation is independent of the others, and all require the same input, so it seems ideal for parallelisation. A quick benchmark revealed the following running times: http://dreixel.net/images/perm/ParList.png (Note the non-linear number of cores at the end of the x-axis.) Apparently there are performance gains with up to 6 cores; adding more cores after this makes the total running time worse. While this might sound bad, do note that all that was necessary to parallelise this algorithm was a one line change: basically, at the point where the list of floats @l@ is generated, it is replaced with @l `using` parList rdeepseq@. This change, together with recompilation using -threaded, is all that is necessary to parallelise this program. Later I performed a more accurate benchmark, this time using the equality function (take two elements and compare them for equality). The first step was to parallelise the equality function, which, again, is a very simple task: -- Tree datatype data Tree a = Leaf | Bin a (Tree a) (Tree a) -- Parallel equality eqTreePar :: Tree Int - Tree Int - Bool eqTreePar Leaf Leaf = True eqTreePar (Bin x1 l1 r1) (Bin x2 l2 r2) = x1 == x2 par l (pseq r (l r)) where l = eqTreePar l1 l2 r = eqTreePar r1 r2 eqTreePar _ _ = False `par` and `pseq` are the two primitives for parallelisation in GHC [5]. The performance graph follows: http://dreixel.net/images/perm/ParEq.png (This time I ran the benchmark several times; the error bars on the graph are the standard deviations.) Again we get performance improvements with up to 6 cores, and after that performance decreases. What I find really nice is the improvement with two cores, which is almost a 50% decrease in running time. The ratios for 2 to 4 cores wrt. the running time with 1 core are 0.52, 0.39, and 0.35, respectively. This is really good for such a simple change in the source code, and most people only have up to 4 cores anyway. In any case, the results of this (very preliminary) experiment seem to indicate that GHC's SMP parallelism is not particularly optimized for a high number of cores (yet). I'm planning to explore this line of research further, and I'm hoping to be able to conduct more experiments in the near future. Feel free to contact me if you want more information on what I've done. Cheers, Pedro [1] http://www.haskell.org/ghc/ [2] http://www.haskell.org/ghc/docs/latest/html/users_guide/using-smp.html [3] http://hackage.haskell.org/package/cabal-install [4] http://hackage.haskell.org [5] http://hackage.haskell.org/packages/archive/parallel/latest/doc/html/Control-Parallel.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] SMP parallelism gains inferior than expected
(Forwarding to haskell-cafe) Hi, I have a program that computes a matrix of Floats of m rows by n columns. Computing each Float is relatively expensive. Each line is completely independent of the others, so I thought I'd try some simple SMP parallelism on this code: myFun :: FilePath - IO () myFun fp = do fs - readDataDir fp let process f = readFile' f = parse printLine = putStrLn . foldr (\a b - show a ++ \t ++ b) runDiff l = [ [ diff x y | y - l ] | (x,i) - zip l (map getId fs), myFilter i ] ps - mapM process fs sequence_ [ printLine x | x - runDiff ps *`using` parList rdeepseq* ] So, I'm using parList to evaluate the rows in parallel, and fully evaluating each row. Here are the timings on a Dual Quad Core AMD 2378 @2.4 GHz, ghc-6.12.3, parallel-2.2.0.1: -N time (ms) none1m50 2 1m33 3 1m35 4 1m22 5 1m11 6 1m06 7 1m45 The increase at 7 is justified by the fact that there were two other processes running. I don't know how to justify the small increase at N3, though, but that doesn't matter too much. The problem is that I am not getting the gains I expected (halving at N2, a third at N3, etc.). Is this the best one can achieve with this implicit parallelism, or am I doing something wrong? In particular, is the way I'm printing the results at the end destroying potential parallel gains? Any insights on this are appreciated. Thanks, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: htime-0.1
Hello all, I kept being annoyed at the fact that Windows doesn't come with anything similar to the unix time utility, so I created a small Haskell program that does something similar. I thought this could perhaps be useful to others, so it's now available on Hackage: http://hackage.haskell.org/package/htime-0.1 Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] rewrite rules to specialize function according to type class?
Hello, 2011/2/15 Simon Peyton-Jones simo...@microsoft.com but currently any pragmas in a class decl are treated as attaching to the *default method*, not to the method selector: Thanks for this clarification, I had wondered about this for a while. I think it would also be nice to mention this in the user's guide; currently, http://www.haskell.org/ghc/docs/latest/html/users_guide/rewrite-rules.htmlsays nothing about the semantics of rewrite rules in classes/instances. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] SYB: extending a generic reader with a type class
Hi, I don't think you can do that, since `ext` relies on Typeable and Typeable only works for monomorphic types. Cheers, Pedro On Wed, Feb 2, 2011 at 20:31, Sugar Bzzz sugarbz...@gmail.com wrote: Dear -cafe, Is it possible to extend a generic reader (extR / ext1R from syb) with a type class? For example, let foo :: (Integral a) = SomeMonad a I could write: reader = ... `extR` (foo :: SomeMonad Int) `extR` (foo :: SomeMonad Integer) However, that is tedious. Could I do something like reader = ... `extR` foo and have it apply to all instances of Integral? I hope I am being clear. Thank you. ___ 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] Compiling UHC
Hi Henk-Jan, On Mon, Aug 23, 2010 at 00:15, Henk-Jan van Tuyl hjgt...@chello.nl wrote: L.S., I am trying to compile the current release of UHC (1.0.1); I started with the installation of the most recent version of uulib and uuagc. When running make uhc I received the following message: EH\Util\CompileRun.hs:46:7: Could not find module `UU.DData.Scc': Use -v to see a list of the files searched for. This module is not in the most recent version of uulib, so I installed uulib-0.9.10, but then I received the message: EH\Util\CompileRun.hs:46:7: Could not find module `UU.DData.Scc': It is a member of the hidden package `uulib-0.9.10'. Use -v to see a list of the files searched for. What can I do to get UHC compiled? Yes, I think you really have to use uulib-0.9.10 for the latest released version. Another alternative would be to checkout the HEAD. But if you don't want that, then uninstall uulib-0.9.12 (ghc-pkg unregister uulib-0.9.12) first; GHC should then use uulib-0.9.10 automatically. Cheers, Pedro (I am using Haskell Platform 2010.2.0.0) Regards, Henk-Jan van Tuyl -- http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html -- ___ 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] Tiger compiler in Haskell: annotating abstract syntax tree
Hi Romildo, 2010/7/23 José Romildo Malaquias j.romi...@gmail.com On Tue, Jul 20, 2010 at 09:17:15AM +0200, José Pedro Magalhães wrote: 2010/7/19 José Romildo Malaquias j.romi...@gmail.com I am writing here to ask suggestions on how to annotate an ast with types (or any other information that would be relevant in a compiler phase) in Haskell. Indeed I would suggest the method described in our paper: Martijn van Steenbergen, José Pedro Magalhães, and Johan Jeuring. Generic selections of subexpressions. Paper link: http://dreixel.net/research/pdf/gss_draft.pdf Related hackage package: http://hackage.haskell.org/package/Annotations Annotations-0.1 requires base ==4.1.* and parsec ==3.0.*, but I have base-4.2.0.2 and parsec-3.1.0 on my Gentoo Linux system. Would it work with these new versions of base and parsec? Yes, that version has a problem with the constraints. I think they are too restrictive; probably base = 4 base 4.3 would do. As for parsec, I am not sure, but at least you can easily get parsec-3.0.*, whereas base is more complicated. We will upload a new version soon to fix this. Cheers, Pedro Romildo ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Tiger compiler in Haskell: annotating abstract
Hi Oleg, On Wed, Jul 21, 2010 at 09:36, o...@okmij.org wrote: Jose Pedro Magalhaes wrote: From what I understand, you are using a list of integers to encode a path to a subterm. This is a practical and lightweight implementation, but less type-safe: it is easy to encode annotations that do not correspond to any value. Also, it cannot guarantee, with types alone, that every subterm is annotated. Let us consider the type safety closely. Let us assume a very simple data type: lists of integers of length 10. Suppose we want to add string annotations to the elements. In my solution, I create an IntMap whose key is an integer 0..9 (the index in the original list) and the value is the string annotation. It is true that the type system does not prevent me from adding an annotation for key 11 (which corresponds to no element in the original list) or from forgetting to add annotation for key 7. As I understand it, your approach is to transform the original list of integers into the list of (Int,String) pairs. Now we are sure that each element is paired with an annotation and there are no orphan annotations. The annotation process creates this new list of pairs and returns it. However, how do you get _the type checker_ to ensure that the annotated list does correspond to the original list? That all old elements are present in the annotated list, and in the same order? It all boils down to enforcing the invariant proj al == l where l is the original list, al is the annotation list, and proj is the operation that removes annotations. It is true that my lightweight method generally cannot, in type system, enforce that invariant. (I can still enforce it if I design an appropriate security kernel and prove, _offline_, its correctness). But how could you enforce that invariant *in the type system*? Considering our library approach (using multirec), there is no type-level guarantee that the generic values correspond to their normal counterparts. From the type we can see that they have the same shape, but not that they have the same content. This would be an offline proof: that the embedding-projection pair really is an isomorphism (between normal and generic values). However, this proof is external to the annotations system: it belongs in the generic library (since the library generates the embedding-projection pair automatically), and only needs to be done once. Once the embedding-projection pair has been proven correct, the annotations are shape-correct by construction, and value-correct by the correctness of the generic library. As I understand it, in your system you would need a proof of correctness for every annotated type. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Tiger compiler in Haskell: annotating abstract syntax tree
Hi José, 2010/7/19 José Romildo Malaquias j.romi...@gmail.com I am writing here to ask suggestions on how to annotate an ast with types (or any other information that would be relevant in a compiler phase) in Haskell. As an example, consider the simplified ast types: data Exp = IntExp Integer | VarExp Symbol | AssignExp Symbol Exp | IfExp Exp Exp (Maybe Exp) | CallExp Symbol [Exp] | LetExp [Dec] Exp data Dec = TypeDec Symbol Ty | FunctionDec Symbol [(Symbol,Symbol)] (Mybe Symbol) Exp | VarDec Symbol (Maybe Symbol) Exp Expressions can have type annotations, but declarations can not. Comments? Indeed I would suggest the method described in our paper: Martijn van Steenbergen, José Pedro Magalhães, and Johan Jeuring. Generic selections of subexpressions. Paper link: http://dreixel.net/research/pdf/gss_draft.pdf Related hackage package: http://hackage.haskell.org/package/Annotations Something like what Malcolm proposed (adding one extra constructor) would also be possible generically, but it would be more similar to how we add meta-variables in our generic rewriting library (ask for more details if you're interested in this alternative). Cheers, Pedro Regards, Romildo -- Computer Science Department Universidade Federal de Ouro Preto, Brasil ___ 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: Tiger compiler in Haskell: annotating abstract syntax tree
Hi Oleg, From what I understand, you are using a list of integers to encode a path to a subterm. This is a practical and lightweight implementation, but less type-safe: it is easy to encode annotations that do not correspond to any value. Also, it cannot guarantee, with types alone, that every subterm is annotated. Our solution, on the other way, requires more intrusive changes to the user's datatype. Cheers, Pedro On Tue, Jul 20, 2010 at 11:06, o...@okmij.org wrote: Jose' Romildo Malaquias wrote: I am writing here to ask suggestions on how to annotate an ast with types (or any other information that would be relevant in a compiler phase) in Haskell. There is also a general way of annotating AST post factum, described in http://okmij.org/ftp/Algorithms.html#tree-annot The method lets one attach arbitrarily many annotations to an already built AST, *without* the need to change the definition of the datatype. One does not even have to anticipate annotations! The method would work with your AST data Exp = IntExp Integer | VarExp Symbol | AssignExp Symbol Exp as _it is_, without any modifications -- neither to the data type definition, nor to the tree. The method was demonstrated when writing a compiler of sorts: annotating an AST with an inferred type for each node. If the type inference fails, we can still print out the inferred types for the good subexpressions. ___ 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] GADTs and Scrap your Boilerplate
Hi Oscar, On Sat, May 15, 2010 at 22:19, Oscar Finnsson oscar.finns...@gmail.comwrote: (...) I guess my questions are: 1. Is it possible to combine GADTs with Scrap your Boilerplate? Your GADT encodes an existential datatype. The closest attempt to encode existential types in (something like) SYB that I know of is in Section 5.3 of Alexey's PhD thesis [1]. Having said that, he uses the spine view, which makes the generic view in SYB explicit, but this has never been packaged as a library. So I'm afraid the answer is no. The link above might still be useful for your understanding of why this is a complex problem, though. Cheers, Pedro [1] http://igitur-archive.library.uu.nl/dissertations/2009-0518-200422/UUindex.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Data instance for a GADT
Hi Ozgur, At least template-haskell-2.4.0.0 (which comes with GHC 6.12) has syntax for type equality constraints [1], so I'm guessing it should support GADTs (I haven't actually tested it). It also has syntax for type families. Cheers, Pedro [1] http://hackage.haskell.org/packages/archive/template-haskell/2.4.0.0/doc/html/Language-Haskell-TH-Syntax.html#t%3ACxt On Wed, Apr 14, 2010 at 11:53, Ozgur Akgun ozgurak...@gmail.com wrote: Seeing this old thread[1], I hope something happened towards enabling this. Does anybody know the current status about using TH on GADTs? [1] http://www.haskell.org/pipermail/template-haskell/2006-August/000567.html On 14 April 2010 10:32, Ozgur Akgun ozgurak...@gmail.com wrote: answering to myself: I guess this is related: http://hackage.haskell.org/trac/ghc/ticket/3497 On 14 April 2010 10:13, Ozgur Akgun ozgurak...@gmail.com wrote: Cafe, How can I provide a Data instance for a GADT? I am trying to TH on it, and Uniplate requires Data. I tried StandaloneDeriving, but it seems not to work. Best, -- Ozgur Akgun -- Ozgur Akgun -- Ozgur Akgun ___ 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: cabal: other-modules
Hi, On Thu, Apr 15, 2010 at 14:40, Johannes Waldmann waldm...@imn.htwk-leipzig.de wrote: What happened was this: 1. add some modules to a library (but forget to mention them in the cabal file), then (in the lib source dir, without cleaning/reconfiguring) cabal install --global (runs without complaint) 2. re-compile an application that uses the library (cabal configure cabal build): this gave undefined symbol errors (for things from the added modules) Just to say that this has happened to me very often as well, on Windows. The first time it took me quite some time to realize what was going wrong... Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] SYB/Generics documentation inaccessible
A few days ago I changed the links from the SYB wiki [1] to point to an archived version of the vu.nl webpage: http://web.archive.org/web/20080622204226/http://www.cs.vu.nl/boilerplate/ But it would be nice to have the webpage up again, somewhere. Cheers, Pedro [1] http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/SYB On Tue, Feb 2, 2010 at 21:23, Arne D Halvorsen arne@gmail.com wrote: I have tried to access a few of the documents on generics that are referred to from wikipedia, from the GHC documentation, from hackage and from the wiki. These documents (on vu.nl, subdirectory boilerplate and strafunski) are apparently forbidden to me, and have been for some weeks. I tried to mail a webmaster and some other mentioned mail addresses, but the mails bounced. Could somebody make the docs accessible, or should it be re-hosted on Hackage? Regards Arne D Halvorsen ___ 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: could we get a Data instance for Data.Text.Text?
Hi Jeremy, As Neil Mitchell said before, if you really don't want to expose the internals of Text (by just using a derived instance) then you have no other alternative than to use String conversion. If you've been using it already and performance is not a big problem, then I guess it's ok. Regarding the Serialize issue, maybe I am not understanding the problem correctly: isn't that just another generic function? There are generic implementations of binary get and put for at least two generic programming libraries in Hackage [1, 2], and writing one for SYB shouldn't be hard either, I think. Then you could have a trivial way of generating instances of Serialize, namely something like instance Serialize MyType where getCopy = gget putCopy = gput and you could provide Template Haskell code for generating these. Or even just do instance (Data a) = Serialize a where ... if you are willing to use OverlappingInstances and UndecidableInstances... Cheers, Pedro [1] http://hackage.haskell.org/packages/archive/regular-extras/0.1.2/doc/html/Generics-Regular-Functions-Binary.html [2] http://hackage.haskell.org/packages/archive/multirec-binary/0.0.1/doc/html/Generics-MultiRec-Binary.html On Tue, Jan 26, 2010 at 03:16, Jeremy Shaw jer...@n-heptane.com wrote: On Sun, Jan 24, 2010 at 5:49 AM, Neil Mitchell ndmitch...@gmail.comwrote: Hi, The problem with Data for Text isn't that we have to write a new instance, but that you could argue that proper handling of Text with Data would not be using a type class, but have special knowledge baked in to Data. That's far worse than the Serialise problem mentioned above, and no one other than the Data authors could solve it. Of course, I don't believe that, but it is a possible interpretation. Right.. that is the problem with Text. Do you think the correct thing to do for gunfold and toConstr is to convert the Text to a String and then call the gufold and toConstr for String? Or something else? The Serialise problem is a serious one. I can't think of any good solutions, but I recommend you give knowledge of your serialise class to Derive (http://community.haskell.org/~ndm/derive/http://community.haskell.org/%7Endm/derive/) and then at least the instances can be auto-generated. Writing lots of boilerplate and regularly ripping it up is annoying, setting up something to generate it for you reduces the pain. We currently use template haskell to generate the Serialize instances in most cases (though some data types have more optimized encodings that were written by hand). However, you must supply the Version and Migration instances by hand (they are super classes of Serialize). I am all for splitting the Serialize stuff out of happstack .. it is not really happstack specific. Though I suspect pulling it out is not entirely trivial either. I think the existing code depends on syb-with-class. - jeremy ___ 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] Largest types in SYB
Hello Paul, On Fri, Dec 18, 2009 at 16:47, Paul Keir pk...@dcs.gla.ac.uk wrote: (...) I'm enjoying using SYB, and had hoped to use only functions from the package, but couldn't find a way; and this does the job for now. I've also seen that there are many other approaches to generic programming than SYB (even for AST transformations in particular) but I wanted to understand SYB first. I'm interested to know if anyone has a more elegant SYB solution. I think this looks fine. The package only provides basic generic functionality, but when you need something more specific you can use the basics to write your own generic functions, which is what you did. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: deepseq-1.0.0.0
Hello, The release of the regular library for generic programming on Hackage [1] also contains a form of deep seq [2]. This means that you don't even have to write the definition of 'deepseq', you can just use 'gdseq' (assuming you have used Template Haskell to derive the generic representations for your types). Cheers, Pedro [1] http://hackage.haskell.org/package/regular [2] http://hackage.haskell.org/packages/archive/regular/0.2.1/doc/html/Generics-Regular-Functions-Seq.html#t%3ASeq On Tue, Nov 17, 2009 at 12:04, Roel van Dijk vandijk.r...@gmail.com wrote: On Tue, Nov 17, 2009 at 12:00 PM, Simon Marlow marlo...@gmail.com wrote: I've just uploaded deepseq-1.0.0.0 to Hackage This is great! I often use rnf to fully evaluate some expression where I didn't need parallelism at all. Time to update some packages. Thank you, Roel ___ Libraries mailing list librar...@haskell.org http://www.haskell.org/mailman/listinfo/libraries ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Documentation (was: ANN: text 0.5, a major revision of the Unicode text library)
Hi, While I agree that the documentation of Data.Generics is not perfect, I do not think it is possible to have the haddock documentation be self-contained. For a thorough understanding of syb, a user has to read the two initial papers, which are linked from the haddock documentation. I also do not think it's reasonable to explain all the details beyond monads in the Control.Monad haddock, for instance. For the problem at hand (a Data instance for Text), I can only say that generic programming and abstract datatypes do not mix too well (although there is work on the area, see [1]). Generics work by exploiting the structure of types, and if that structure is explicitly kept hidden then (rather ad hoc) workarounds have to be used. See, for example, the Data instance for Array: -- The Data instance for Array preserves data abstraction at the cost of -- inefficiency. We omit reflection services for the sake of data abstraction. instance (Typeable a, Data b, Ix a) = Data (Array a b) where gfoldl f z a = z (listArray (bounds a)) `f` (elems a) toConstr _ = error toConstr gunfold _ _ = error gunfold dataTypeOf _ = mkNorepType Data.Array.Array Cheers, Pedro [1] http://www.comlab.ox.ac.uk/publications/publication1385-abstract.html On Sun, Oct 11, 2009 at 14:58, John Lato jwl...@gmail.com wrote: For anyone writing introductions to generic programming, take this as a plea from Haskellers everywhere. If one of the RWH authors can't understand how to make use of these techniques, what hope do the rest of us have? John Lato P.S. Some might wryly note that I'm the maintainer of a package which is also known for incomprehensible documentation. To which I would reply that our effort is much newer, I consider it a problem, and it's being worked on, contrasted to the state of GP where similarly impenetrable documentation has been and continues to be the norm. From: Bryan O'Sullivan b...@serpentine.com I think maybe someone else will have to take a crack at a Data instance for Text, because the documentation for Data.Data is not written in English. In its syntax and structure, it closely hews to what we think of as English, but it is the kind of documentation that can only be understood by someone who already knows what it is going to say. This is an exemplar of my experience with the cottage industry of generic programming in Haskell: I'd really quite like to use the stuff, but for goodness's sake, o beloved researchers, please aim your expository papers at non-specialists once in a while. An endless chain of papers of the form my technique, which you won't understand, is better than this other technique, which you haven't read about and won't anyway understand, in subtle ways that you won't understand does not feel to me like progress. Yours in some misery and frustration, Bryan. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Re[2]: [Haskell-cafe] Any generic serializer to String? was: Any working example of using genericserialize?
Hi Dimitry, On Thu, Oct 1, 2009 at 05:23, Dimitry Golubovsky golubov...@gmail.comwrote: OK, I got it to work with gread/gshow. However I have noticed this: *Main (gread $ gshow $ FuncExpr 0 [] (EmptyStmt 0)) :: [(Expression Int, String)] [(FuncExpr 0 [] (EmptyStmt 0),)] vs. *Main (gread $ gshow $ FuncExpr () [] (EmptyStmt ())) :: [(Expression (), String)] [] Or even narrower: *Main (gread $ gshow 1)::[(Int, String)] [(1,)] vs. *Main (gread $ gshow ())::[((), String)] [] that is, the unit type does not work well with gread/gshow, likely because inner parentheses are not parsed as a constructor. *Main gshow () (()) Is this a known bug? I don't think this was noticed before. I wrote it down on the SYB tracker [1]. It should be fixed for the next release. Thanks, Pedro [1] http://code.google.com/p/scrapyourboilerplate/issues/detail?id=9 Thanks. On Wed, Sep 30, 2009 at 10:19 AM, Dimitry Golubovsky golubov...@gmail.com wrote: Bulat, OK, gread/gshow seem to be like the basis primitives. If they work properly, then it is what is needed. Thanks. On 9/30/09, Bulat Ziganshin bulat.zigans...@gmail.com wrote: Hello Max, Wednesday, September 30, 2009, 5:53:37 PM, you wrote: afaik, SYB just provides gshow/gread functions what serialize any Data instance to String -- Dimitry Golubovsky Anywhere on the Web ___ 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] Ambiguous type variable with subclass instance (also: is there a better way to do this?)
Hey Andy, On Thu, Sep 17, 2009 at 15:40, Andy Gimblett hask...@gimbo.org.uk wrote: Now, some of those algebraic data type types happen to be enumerations; in this case, my idea is to list the constructors, with the rule that each constructor's position in the list is the Int which gets converted into that constructor. class Enumerated a where constructors :: [a] E.g. here's a type Bar with three constructors: data Bar = X | Y | Z deriving (Show) instance Enumerated Bar where constructors = [X, Y, Z] (This is certainly ugly. Any suggestions?) |constructors| is expressible in SYB: {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE FlexibleContexts #-} module Test where import Data.Data import Data.Generics.Aliases (extB) -- | Construct the empty value for a datatype. For algebraic datatypes, the -- leftmost constructor is chosen. empty :: forall a. Data a = a empty = general `extB` char `extB` int `extB` integer `extB` float `extB` double where -- Generic case general :: Data a = a general = fromConstrB empty (indexConstr (dataTypeOf general) 1) -- Base cases char= '\NUL' int = 0 :: Int integer = 0 :: Integer float = 0.0:: Float double = 0.0:: Double -- | Return a list of values of a datatype. Each value is one of the possible -- constructors of the datatype, populated with 'empty' values. constrs :: forall a. Data a = [a] constrs = general `extB` char `extB` int `extB` integer `extB` float `extB` double where -- Generic case general :: Data a = [a] general = map (fromConstrB empty) (dataTypeConstrs (dataTypeOf (unList general))) where unList :: Data a = [a] - a unList = undefined -- Base cases char= \NUL int = [0 :: Int] integer = [0 :: Integer] float = [0.0 :: Float] double = [0.0 :: Double] |constrs| is similar to your |constructors|, but in this way you get it for free for any datatype with a |Data| instance. Then I guess your |convert| is: convert :: forall a. Data a = Int - Maybe a convert n = let cs :: [a] cs = constrs in if (length cs n) then (Just (cs !! n)) else Nothing Note that ScopedTypeVariables are essential to typecheck this code. Cheers, Pedro ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Ambiguous type variable with subclass instance (also: is there a better way to do this?)
Hello, On Thu, Sep 17, 2009 at 16:05, Daniel Fischer daniel.is.fisc...@web.dewrote: Am Donnerstag 17 September 2009 15:56:03 schrieb José Pedro Magalhães: Hey Andy, On Thu, Sep 17, 2009 at 15:40, Andy Gimblett hask...@gimbo.org.uk wrote: Now, some of those algebraic data type types happen to be enumerations; in this case, my idea is to list the constructors, with the rule that each constructor's position in the list is the Int which gets converted into that constructor. class Enumerated a where constructors :: [a] E.g. here's a type Bar with three constructors: data Bar = X | Y | Z deriving (Show) instance Enumerated Bar where constructors = [X, Y, Z] (This is certainly ugly. Any suggestions?) |constructors| is expressible in SYB: Wow. What about data Bar = X | Y | Z deriving (Show, Eq, Ord, Enum, Bounded) instance Enumerated Bar where constructors = [minBound .. maxBound] ? Oh yes, that will certainly work for this very simple datatype. However, one cannot automatically derive instances of |Bounded| for datatypes with non-nullary constructors. Cheers, Pedro ___ 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] Externally derive instance of Data?
Hi Dimitry, I think what you want is stand-alone deriving: http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#stand-alone-deriving Cheers, Pedro On Fri, Sep 11, 2009 at 16:29, Dimitry Golubovsky golubov...@gmail.comwrote: Hi, Given a datatype defined somewhere in a third-party package, without deriving (Data) specified. Is it possible, in my module which is importing that datatype from that package, to auto-derive instance of Data for the said datatype? The goal is not to recompile the package just because an auto-derived instance is needed. Or no way other than to recompile the package? Thanks. -- Dimitry Golubovsky Anywhere on the Web ___ 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] Deconstructing types
Hello Louis, On Tue, Sep 8, 2009 at 19:06, Louis Wasserman wasserman.lo...@gmail.comwrote: Sean, The answer is, I'm working on a recently semi-released package called TrieMap. Is that similar to what is done in [1]? A draft paper [2] also refers that implementation. Cheers, Pedro [1] http://www.haskell.org/haskellwiki/GHC/Indexed_types#An_associated_data_type_example [2] http://www.cse.unsw.edu.au/~chak/project/generics/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Generics for constructing Rows
Hello, On Thu, Aug 20, 2009 at 16:54, Max Desyatov explicitc...@googlemail.comwrote: Sean Leather leat...@cs.uu.nl writes: I'm not sure the problem you're running into is strictly a generic programming (GP) one. Typically, GP takes code that is often written and generalizes it, so that it doesn't have to be written for multiple datatypes. That seems to be GP problem, as your solution doesn't scale well when I wan't to add/remove/change fields in the `Row` record. The perfect way as I see it, would be just editing `Row` data declaration, nothing else. Studying few papers about GP in Haskell, I reckon this could be represented as generic traversal, using my `Row` declaration with `Either`. I don't see really good way to write a generic producer from `[String]` to version of `Row` without `Either`. But SYB doesn't provide a way for passing type-class-parametric functions to gmapT, and SYB-with-class has large overhead of its usage. I don't have enough time to find out how this can be written in SYB-with-class, if it really can be written. The restriction of EMGM was described in my initial message. Indeed SYB doesn't work here because Typeable-based run-time type comparison only works for monomorphic types. Doing something like readRow l = gmapT (mkT (\(Left (Just ri) :: E Name) - Right $ l `atMay` ri = readMay)) would work, but this, of course, is not what you want. I'm guessing the polymorphic typeOf previously described by Oleg [1] could help here, were it integrated in SYB. I don't think syb-with-class will help you here, since it only adds modularity to the type-based function extension. I think you would still have to write a case for every field in the Row record. Multirec would possibly work, were it not for the fact that it doesn't support parametric datatypes yet... Cheers, Pedro [1] http://osdir.com/ml/haskell-cafe@haskell.org/2009-03/msg00212.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Adding a field to a data record
Hello Henry, The paper A Lightweight Approach To Datatype-Generic Rewriting [1] describes a way to generically add a constructor to any regular datatype using type-indexed datatypes [2]. A similar technique could be used to add a new field to each constructor. Then you get something like: data Foo type Extended f = ... |Extended Foo| represents your |Foo| datatype with an added |z| field of type |Int|. Since the underlying generic programming library used (regular [3]) has Template Haskell generation, you don't even have to write the generic representations for your many datatypes. (As far as I know, SYB does not mix with type-indexed datatypes.) Cheers, Pedro [1] Thomas van Noort, Alexey Rodriguez, Stefan Holdermans, Johan Jeuring, Bastiaan Heeren. A Lightweight Approach to Datatype-Generic Rewriting. Submitted to the Workshop on Generic Programming 2008. http://www.cs.uu.nl/wiki/bin/view/Alexey/ALightweightApproachToDatatype-GenericRewriting [2] http://www.iai.uni-bonn.de/~ralf/publications/SCP2004.pdf [3] http://www.cs.uu.nl/wiki/GenericProgramming/Regular On Tue, Jul 28, 2009 at 16:29, Henry Laxen nadine.and.he...@pobox.comwrote: Dear Group, It seems to me this should be easy, but I can't quite figure out how to do it without a lot of typing. Here is the question: Suppose you have a data type like: Data Foo = Foo { a :: Int, b :: Int, ... many other fields ... y :: Int } deriving (Eq, Read, Show, Typeable, Data) Now I would like to add a field z :: Int to the end of Foo. If I have a ton of data out on disk, which I wrote with, say writeFile a.data (show foo) -- where foo is a [Foo] say 1000 long, I would like to get a new a.data file which has a new z::Int field. So far the only way I can think of is to make a new Data Foo1, which includes the z::Int, read in a.data as a list of Foo, write a function like: fooTofoo1 :: Foo - Foo1 fooTofoo1 xx = Foo1 {a = a xx, ... y = y xx, z = 1} then write the file back out, and perhaps use emacs to query-replace all the Foo1's back to Foo's, add the z::Int field back into Foo, and read it back. Please tell me there is a better way. Thanks in advance. Best wishes, Henry Laxen PS: I have read syb1, and syb2 a couple of times now, but so far haven't been able to connect it with this kind of problem. ___ 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] Can you determine a constructor's arity using Data.Typeable and Data.Data?
Hey David, For instance: arity :: (Data a) = a - Int arity = length . gmapQ (const ()) Cheers, Pedro On Thu, Jun 25, 2009 at 17:31, David Fox dds...@gmail.com wrote: Is it possible to determine the arity of a value's constructor? Suppose I have a value x of type data A = B Int | C They typeOf function returns its TypeRep, which contains its type constructor, but I don't see how to decide whether that constructor's arity is 0 or 1. If the type has field names I can look at those using Data.Data.conFields and count them, but if it doesn't I don't see how to do it. -david ___ 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] understanding generics
Hello Anatoly, On Sat, Apr 11, 2009 at 20:44, Anatoly Yakovenko aeyakove...@gmail.comwrote: i am trying to understand how data.data works. How would i traverse the subterms of one type and build another type out of them. something like this: gmapQ (\a - Right a) (Just hello) I am not sure I understand what you're trying to do here. However, in general, 'gmapQ' is used in combination with 'mkQ' or 'extQ'. Those are not in Data.Data: you can import Data.Generics to get everything syb-related. Cheers, Pedro interactive:1:0: Inferred type is less polymorphic than expected Quantified type variable `d' escapes In the first argument of `gmapQ', namely `(\ a - Right a)' In the expression: gmapQ (\ a - Right a) (Just hello) In the definition of `it': it = gmapQ (\ a - Right a) (Just hello) Thanks, Anatoly ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] type-level programming support library
Hello, I suppose Lennart is referring to type-level [1]. But type-level uses functional dependencies, right? There is also tfp [2], which uses type families. In general, how would you say your work compares to these two? Thanks, Pedro [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/type-level [2] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/tfp On Mon, Mar 30, 2009 at 08:22, Lennart Augustsson lenn...@augustsson.netwrote: There is already a library for type level number, called typelevel. It's nice because it uses decimal representation of numbers and can handle numbers of reasonable size. I use it in the LLVM bindings. -- Lennart On Mon, Mar 30, 2009 at 1:07 AM, spoon sp...@killersmurf.com wrote: I've been doing some basic work on a support library for type level programming ( see http://hackage.haskell.org/trac/summer-of-code/ticket/1541 ). I know there have been similar attempts using fundeps ( Edward Kmett showed me some of his work, but I've lost the address... ) but this approach uses type families. Anyway, I would like to hear your critique! Currently I have higher order type functions and ad-hoc parametrized functions. Here's what foldl looks like: type family Foldl ( func :: * - * - * ) val list type instance Foldl func val ( Cons first rest ) = Foldl func ( Eval ( func val first ) ) rest type instance Foldl func val Nill = val Notice the use of Eval - this is a trick to enable us to pass around data with kind * - *, or whatever, and then trip this into becoming a value. Here's an example, using this trick to define factorial: -- multiplication type family Times x y type instance Times x Zero = Zero type instance Times x ( Succ y ) = Sum x ( Times x y ) -- The first order function version of Times data TimesL x y -- Where what Eval forced TimesL to become. type instance Eval ( TimesL x y ) = Times x y -- multiplies all the elements of list of Nat together type Product l = Foldl TimesL ( Succ Zero ) l -- here list to creates a list from ( Succ Zero ) to the given number type Factorial x = Product ( ListTo x ) We can now use the function like this: *TPrelude result ( ) :: Factorial ( Succ ( Succ ( Succ ( Zero ) ) ) ) Succ (Succ (Succ (Succ (Succ (Succ Zero) Using the parametrized types kinda reminds me of programming in Erlang: -- What would conventionally be the monad type class, parametized over m type family Bind m ma ( f :: * - * ) type family Return m a type family Sequence m ma mb Here's the maybe monad: -- Monad instance type instance Bind ( Maybe t ) Nothing f = Nothing type instance Bind ( Maybe t ) ( Just a ) f = Eval ( f a ) type instance Sequence ( Maybe t ) Nothing a = Nothing type instance Sequence ( Maybe t ) ( Just a ) b = b type instance Return ( Maybe t ) a = Just a type instance Eval ( Just x ) = Just x Here's an example: *TPrelude result ( ) :: Bind ( Maybe Nat ) ( Just Zero ) Just Just Zero For more information and to download the loose collection of module implementing this please see: http://www.killersmurf.com/projects/typelib John Morrice ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: is there any reason why Language.C.Syntax.AST.CTranslUnit doesn't derive show?
Hello Anatoly, Bear in mind that gshow behaves a bit differently from the regular show (namely regarding parenthesis and efficiency). You can also use standalone deriving [1] to derive Show for those datatypes. Cheers, Pedro [1] http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#stand-alone-deriving On Sat, Mar 28, 2009 at 02:07, Anatoly Yakovenko aeyakove...@gmail.comwrote: ah, i am guessing its because you can use Data.Generics.gshow to do the same thing. Seems like that library will come in handy when manipulating the AST, pretty cool stuff. On Fri, Mar 27, 2009 at 5:53 PM, Anatoly Yakovenko aeyakove...@gmail.com wrote: is there any reason why Language.C.Syntax.AST.CTranslUnit doesn't derive show? I would like to look at the data structure it generates. It's a lot easier to experiment it when i can write a template C file, print out the AST and then modify that data structure directly, instead of trying to grok the library. Thanks for your great work btw, the parser is pretty sweet. Anatoly ___ 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] Confused by SYB example with zipping
Hello Henry, Changes to GHC regarding the treatment of higher-rank types required a few changes to that test too. You have to eta-expand the application of mkTT and give it a type signature. Therefore, main becomes print $ gzip (\x y - mkTT maxS x y) genCom1 genCom2 and you have to add the type signature mkTT :: (Typeable a, Typeable b, Typeable c) = (a - a - a) - b - c - Maybe c . Then this example should work. As to why exactly these changes are necessary, you might want to check the GHC manual section on arbitrary-rank polymorphism ( http://haskell.org/ghc/docs/latest/html/users_guide/other-type-extensions.html#universal-quantification ). Cheers, Pedro On Sat, Feb 14, 2009 at 21:55, Henry Laxen nadine.and.he...@pobox.comwrote: Dear Group, When trying to run the example at: http://www.cs.vu.nl/boilerplate/testsuite/gzip/Main.hs ghc 6.10.1 says A pattern type signature cannot bind scoped type variables `a' unless the pattern has a rigid type context In the pattern: f :: a - a - a In the definition of `mkTT': mkTT (f :: a - a - a) x y = case (cast x, cast y) of { (Just (x' :: a), Just (y' :: a)) - cast (f x' y') _ - Nothing } In the definition of `main': main = print $ gzip (mkTT maxS) genCom1 genCom2 where genCom1 = everywhere (mkT (double Joost)) genCom genCom2 = everywhere (mkT (double Marlow)) genCom double x (E (p@(P y _)) (S s)) | x == y = E p (S (2 * s)) double _ e = e maxS (S x) (S y) = S (max x y) Failed, modules loaded: CompanyDatatypes. - I must admit I don't really know what to make of this. Any insights would be appreciated. Thanks. Henry Laxen ___ 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] simple generic / data view library?
Hello Conal, What you've done looks very much like the Regular datatype [1] in the rewriting library [2]. The rewriting library, as its name indicates, is very much targeted at rewriting. For a more complete library using a sum of products view (and without type synonyms), try the new release of EMGM [3]. Cheers, Pedro [1] http://hackage.haskell.org/packages/archive/rewriting/0.1/doc/html/Generics-Regular-Rewriting-Representations.html#t%3ARegular [2] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/rewriting [3] http://www.cs.uu.nl/wiki/bin/view/GenericProgramming/EMGM 2008/11/18 Conal Elliott [EMAIL PROTECTED] Is there a simple existing library that provides views of data types in terms of unit, product and sum? Here's what I threw together for my own use. I used associated types, though functional dependencies would work as well. class HasView t where type View t view :: t - View t unview :: View t - t -- View instances instance HasView (Maybe a) where type View (Maybe a) = Either () a view Nothing = (Left ()) view (Just a) = (Right a) unview (Left ())= Nothing unview (Right a)= (Just a) instance HasView [a] where type View [a] = Either () (a,[a]) view [] = (Left ()) view (a:as) = (Right (a,as)) unview (Left ()) = [] unview (Right (a,as)) = (a:as) onView2 :: (HasView a, HasView b, HasView c) = (View a - View b - View c) - (a - b - c) onView2 op a b = unview (view a `op` view b) Thanks, - Conal ___ 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] Proposal for associated type synonyms in Template Haskell
Hello Thomas, I see this is a proposal for a partial implementation of #1673 ( http://hackage.haskell.org/trac/ghc/ticket/1673). Maybe it would be good if the remaining syntax (associated datatypes and type families) would also be defined and implemented in TH. Or maybe there isn't much demand for this?... Cheers, Pedro On Wed, Nov 5, 2008 at 15:57, Thomas van Noort [EMAIL PROTECTED] wrote: Hello, Recently, we released a library on Hackage for generic rewriting (package rewriting if you are curious). The user of the library is expected to define type class instances to enable rewriting on his or her own datatypes. As these instances follow the datatype declarations closely, we tried to generate the instances using Template Haskell. Unfortunately, associated type synonyms are not yet supported by TH. After a presentation at the WGP'08, Simon encouraged us to write a proposal about adding associated type synonyms to TH, so that it can be added to GHC. So, here is our proposal. The TH AST must allow 1) kind declarations of associated type synonyms in class declarations and 2) their definitions in instance declarations. For example, class Foo a where type Bar a :: * instance Foo Int where type Bar Int = String The TH library defines a datatype Dec which contains a constructor for class declarations and instance declarations: data Dec = ... | ClassD Cxt Name [Name] [FunDep] [Dec] | InstanceD Cxt Type [Dec] ... 1) Associated type synonym kind declarations We suggest to add a constructor to the Dec type: ... | AssocTySynKindD Name [Name] (Maybe Kind) ... assocTySynKindD :: Name - [Name] - Maybe KindQ - DecQ The first field is the name of the associated type synonym, the second field is a list of type variables, and the third field is an optional kind. Since kinds are not yet defined in TH, we have to add some kind of kind definition (pun intended): data Kind = StarK | ArrowK Kind Kind type KindQ = Q Kind starK :: KindQ arrowK :: KindQ - KindQ - KindQ We explicitly choose not to reuse the Type type to define kinds (i.e., type Kind = Type as in GHC) since we think a separation between the two worlds is much clearer to the users of TH. 2) Associated type synonym definitions We suggest to add another constructor to the Dec type: ... | AssocTySynD Name [Type] Type ... assocTySynD :: Name - [TypeQ] - TypeQ - DecQ The first field is the name of the type synonym, the second field is a list of type arguments, and the third field is the body of the type synonym. We would like to hear your comments to this proposal. Regards, Thomas ___ 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] Hackage Improvement Ideas
I think at least some sort of statistics of visits and downloads of a package would be very useful, also for the developers to have an idea of how many people are using the package. Pedro On Thu, Oct 23, 2008 at 13:12, Jason Dagit [EMAIL PROTECTED] wrote: Hello, I was thinking of fun little projects people could work on to improve Hackage: 1) Popularity statistics -- like debian's popcon, gives stats on how many people have which packages from hackage installed 2) Per package ratings and feedback listed on the page for each package 3) A way to mark a package as should be removed 4) All the hackage pages should be wiki editable -- for example, the intro page refers to cabal-install as experimental but I think it's moved beyond that point but I'm not sure how to edit that sentence. What else should hackage do? Who wants to claim one of the above earn some serious karma? Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANN: Haskore tutorial (programming music using Haskell)
Hi Jinjing, I remember having written a report on Haskore some years ago, together with a classmate. I think that the example of transformations in twelve-tone technique (see [1]) is one that looks very nice in Haskore due to its simplicity. It's also simple to present to people who do not know music theory, but are (minimally) mathematically inclined. Cheers, Pedro [1] http://en.wikipedia.org/wiki/Twelve-tone_technique#Tone_row On Tue, Aug 5, 2008 at 10:59, jinjing [EMAIL PROTECTED] wrote: Hi there, Here's the project link: http://github.com/nfjinjing/haskore-guide/tree/master/doc/index.markdown I found Haskore pretty fun :) so I'm documenting it while learning it. Please don't hesitate to give suggestions / corrections. Questions: * How much music theory should be there ? ( I'm gonna learn those anyway ) * What kind of examples would be cool ? regards, jinjing ___ 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