[Haskell-cafe] How unique is Unique
Hello! Lacking a proper blog, I've written some notes about Data.Unique here: http://community.haskell.org/~emax/darcs/MoreUnique/ This describes a real problem that makes Data.Unique unsuitable for implementing observable sharing. The document also proposes a solution that uses time stamps to generate symbols that are more unique. Does anyone have any comments on the proposed solution? Are there any alternatives available? Thanks! / Emil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How unique is Unique
On 27 May 2011, at 08:35, Emil Axelsson wrote: Hello! Lacking a proper blog, I've written some notes about Data.Unique here: http://community.haskell.org/~emax/darcs/MoreUnique/ This describes a real problem that makes Data.Unique unsuitable for implementing observable sharing. Looking at the source for Data.Unique shows that its implemented as an Integer, starting at 0, when the IO monad is started - so the values are only unique within a single I/O run, and are definitely not comparable across runs... The document also proposes a solution that uses time stamps to generate symbols that are more unique. Does anyone have any comments on the proposed solution? Are there any alternatives available? I haven't had time to look at that part yet Thanks! / Emil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Andrew Butterfield Tel: +353-1-896-2517 Fax: +353-1-677-2204 Foundations and Methods Research Group Director. School of Computer Science and Statistics, Room F.13, O'Reilly Institute, Trinity College, University of Dublin http://www.cs.tcd.ie/Andrew.Butterfield/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How unique is Unique
2011/5/27 Emil Axelsson e...@chalmers.se: Does anyone have any comments on the proposed solution? Are there any alternatives available? It might be unsuitable where an administrator can change the system's time while the program is running. David. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Strange Type Error
OK thanks everybody ! On Thu, May 26, 2011 at 12:14 PM, Brandon Allbery allber...@gmail.comwrote: On Thu, May 26, 2011 at 06:10, Christopher Done chrisd...@googlemail.com wrote: This kicks everyone in the butt at least once. It would be good if GHC could point it out, as mine (6.12.3) just complains about no instance. Maybe GHC7 does point it out. It's a waste of people's time otherwise. I think the Haskell standards committee is moving in the direction of eliminating it as being the wrong solution to the problem. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel compilation and execution?
Hi Michael, OpenMP is a very different beast, and was developed to help get over the shortcomings that languages like C and FORTRAN have with respect to parallel and concurrent programming (pthreads were about all there was before OpenMP). OpenMP lets you specify regions of code that should be run in multiple threads at once, each with a unique ID. Here is an example of (part of) a parallel merge sort I've been working on static void pmergesort(long int * in, long int * tmp, long int n, int nthread) { long int nhalf = n/2; if(n = N_small) { insertsort1(in, n); return; } if(nthread 1) { #pragma omp parallel num_threads(2) { if(omp_get_thread_num() == 0) pmergesort(tmp, in, nhalf, nthread1); else pmergesort(tmp+nhalf, in+nhalf, n-nhalf, nthread1); } } else { mergesort3(tmp, in, nhalf); mergesort3(tmp+nhalf, in+nhalf, n-nhalf); } merge( tmp, in, nhalf, n); } The approach that Control.Concurrent takes is very different, preferring a style where the programmer says what things might be advantageous to run in parallel, but the runtime makes no guarantees that they will be, allowing the programmer to break work down into smaller chunks, and letting the runtime sort out which parts should be run concurrently. This allows for a much easier style of parallel programming, but is only really possible in a pure language like Haskell. On a side note, the Cilk language, which adds a small number of keywords like fork and sync to the C language takes an approach closer to what Control.Parallel does, but it's not a graceful, and IMO not as easy to use. Hope that helps. I've been having a lot of fun over the last few weeks playing with OpenMP for a university assignment, and I've got to say I greatly prefer the haskell way of doing things. Cheers, Alex Mason On 27/05/2011, at 10:23, michael rice wrote: Are the tools of Control.Parallel comparable to OpenMP? Michael --- On Thu, 5/26/11, michael rice nowg...@yahoo.com wrote: From: michael rice nowg...@yahoo.com Subject: Re: [Haskell-cafe] Parallel compilation and execution? To: David Virebayre dav.vire+hask...@gmail.com Cc: Daniel Fischer daniel.is.fisc...@googlemail.com, haskell-cafe@haskell.org Date: Thursday, May 26, 2011, 9:32 AM Fair question. I copied the parallel version from: http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html but pulled the non-parallel version from a text. Michael --- On Thu, 5/26/11, David Virebayre dav.vire+hask...@gmail.com wrote: From: David Virebayre dav.vire+hask...@gmail.com Subject: Re: [Haskell-cafe] Parallel compilation and execution? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org, Daniel Fischer daniel.is.fisc...@googlemail.com Date: Thursday, May 26, 2011, 8:56 AM 2011/5/26 michael rice nowg...@yahoo.com Thank, Daniel Multiple threads are in evidence in my system monitor, but I wonder why I'm getting two different answers, one twice the other. The first is the parallel solution and the second is the non. Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the non-parallel one ? Michael === {- import Control.Parallel nfib :: Int - Int nfib n | n = 1 = 1 | otherwise = par n1 (pseq n2 (n1 + n2 + 1)) where n1 = nfib (n-1) n2 = nfib (n-2) -} nfib :: Int - Int nfib n | n = 1 = 1 | otherwise = nfib (n-1) + nfib (n-2) main = do putStrLn $ show $ nfib 39 = [michael@hostname ~]$ ghc --make -threaded nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o ) Linking nfib ... [michael@hostname ~]$ ./nfib +RTS -N3 204668309 [michael@hostname ~]$ ghc --make nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o ) Linking nfib ... [michael@hostname ~]$ ./nfib 102334155 [michael@hostname ~]$ -Inline Attachment Follows- ___ 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] Parallel compilation and execution?
On 26/05/2011 14:32, michael rice wrote: Fair question. I copied the parallel version from: http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html That is the User Guide for GHC 6.6, incidentally. If you're using a later version of GHC (highly recommended especially for parallel stuff), then you should look at the docs for your version. Cheers, Simon http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.htmlbut pulled the non-parallel version from a text. Michael --- On *Thu, 5/26/11, David Virebayre /dav.vire+hask...@gmail.com/* wrote: From: David Virebayre dav.vire+hask...@gmail.com Subject: Re: [Haskell-cafe] Parallel compilation and execution? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org, Daniel Fischer daniel.is.fisc...@googlemail.com Date: Thursday, May 26, 2011, 8:56 AM 2011/5/26 michael rice nowg...@yahoo.com /mc/compose?to=nowg...@yahoo.com Thank, Daniel Multiple threads are in evidence in my system monitor, but I wonder why I'm getting two different answers, one twice the other. The first is the parallel solution and the second is the non. Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the non-parallel one ? Michael === {- import Control.Parallel nfib :: Int - Int nfib n | n = 1 = 1 | otherwise = par n1 (pseq n2 (n1 + n2 + 1)) where n1 = nfib (n-1) n2 = nfib (n-2) -} nfib :: Int - Int nfib n | n = 1 = 1 | otherwise = nfib (n-1) + nfib (n-2) main = do putStrLn $ show $ nfib 39 = [michael@hostname ~]$ ghc --make -threaded nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o ) Linking nfib ... [michael@hostname ~]$ ./nfib +RTS -N3 204668309 [michael@hostname ~]$ ghc --make nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o ) Linking nfib ... [michael@hostname ~]$ ./nfib 102334155 [michael@hostname ~]$ ___ 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 unique is Unique
On 27/05/2011 08:35, Emil Axelsson wrote: Hello! Lacking a proper blog, I've written some notes about Data.Unique here: http://community.haskell.org/~emax/darcs/MoreUnique/ This describes a real problem that makes Data.Unique unsuitable for implementing observable sharing. The document also proposes a solution that uses time stamps to generate symbols that are more unique. Does anyone have any comments on the proposed solution? Are there any alternatives available? This has nothing to do with Unique, you are simply using unsafePerformIO in an unsafe way. It is called unsafePerformIO for a reason :-) Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel compilation and execution?
Hi Alex, I had previously looked at OpenMP (Fortran) and when I saw par and seq in Control.Parallel I got a sense of common terminology, sections of code that can be executed in parallel and sections of code that must be executed sequentially. I haven't looked at Control.Concurrent yet. The original reason I took a look at Haskell (and Erlang) was multi-core CPUs were becoming common and I wanted to learn to take advantage of them, but Haskell's learning curve has been so steep I've been occupied with learning other aspects of the language and only now have turned again to try my hand at its parallelizing features. Thanks, Michael --- On Fri, 5/27/11, Alex Mason axm...@gmail.com wrote: From: Alex Mason axm...@gmail.com Subject: Re: [Haskell-cafe] Parallel compilation and execution? To: michael rice nowg...@yahoo.com Cc: David Virebayre dav.vire+hask...@gmail.com, haskell-cafe@haskell.org, Daniel Fischer daniel.is.fisc...@googlemail.com Date: Friday, May 27, 2011, 6:05 AM Hi Michael, OpenMP is a very different beast, and was developed to help get over the shortcomings that languages like C and FORTRAN have with respect to parallel and concurrent programming (pthreads were about all there was before OpenMP). OpenMP lets you specify regions of code that should be run in multiple threads at once, each with a unique ID. Here is an example of (part of) a parallel merge sort I've been working on static voidpmergesort(long int * in, long int * tmp, long int n, int nthread){ long int nhalf = n/2; if(n = N_small) { insertsort1(in, n); return; } if(nthread 1) { #pragma omp parallel num_threads(2) { if(omp_get_thread_num() == 0) pmergesort(tmp, in, nhalf, nthread1); else pmergesort(tmp+nhalf, in+nhalf, n-nhalf, nthread1); } } else { mergesort3(tmp, in, nhalf); mergesort3(tmp+nhalf, in+nhalf, n-nhalf); } merge( tmp, in, nhalf, n);} The approach that Control.Concurrent takes is very different, preferring a style where the programmer says what things might be advantageous to run in parallel, but the runtime makes no guarantees that they will be, allowing the programmer to break work down into smaller chunks, and letting the runtime sort out which parts should be run concurrently. This allows for a much easier style of parallel programming, but is only really possible in a pure language like Haskell. On a side note, the Cilk language, which adds a small number of keywords like fork and sync to the C language takes an approach closer to what Control.Parallel does, but it's not a graceful, and IMO not as easy to use. Hope that helps. I've been having a lot of fun over the last few weeks playing with OpenMP for a university assignment, and I've got to say I greatly prefer the haskell way of doing things. Cheers,Alex Mason On 27/05/2011, at 10:23, michael rice wrote: Are the tools of Control.Parallel comparable to OpenMP? Michael --- On Thu, 5/26/11, michael rice nowg...@yahoo.com wrote: From: michael rice nowg...@yahoo.com Subject: Re: [Haskell-cafe] Parallel compilation and execution? To: David Virebayre dav.vire+hask...@gmail.com Cc: Daniel Fischer daniel.is.fisc...@googlemail.com, haskell-cafe@haskell.org Date: Thursday, May 26, 2011, 9:32 AM Fair question. I copied the parallel version from: http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html but pulled the non-parallel version from a text. Michael --- On Thu, 5/26/11, David Virebayre dav.vire+hask...@gmail.com wrote: From: David Virebayre dav.vire+hask...@gmail.com Subject: Re: [Haskell-cafe] Parallel compilation and execution? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org, Daniel Fischer daniel.is.fisc...@googlemail.com Date: Thursday, May 26, 2011, 8:56 AM 2011/5/26 michael rice nowg...@yahoo.com Thank, Daniel Multiple threads are in evidence in my system monitor, but I wonder why I'm getting two different answers, one twice the other. The first is the parallel solution and the second is the non. Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the non-parallel one ? Michael === {-import Control.Parallel nfib :: Int - Intnfib n | n = 1 = 1 | otherwise = par n1 (pseq n2 (n1 + n2 + 1)) where n1 = nfib (n-1) n2 = nfib (n-2)-} nfib :: Int - Int nfib n | n = 1 = 1 | otherwise = nfib (n-1) + nfib (n-2) main = do putStrLn $ show $ nfib 39 = [michael@hostname ~]$ ghc --make -threaded nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o )Linking nfib ... [michael@hostname ~]$ ./nfib +RTS -N3204668309[michael@hostname ~]$ ghc --make nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o )Linking nfib ...[michael@hostname ~]$ ./nfib102334155[michael@hostname ~]$ -Inline Attachment Follows-
Re: [Haskell-cafe] How unique is Unique
2011-05-27 10:44, David Virebayre skrev: 2011/5/27 Emil Axelssone...@chalmers.se: Does anyone have any comments on the proposed solution? Are there any alternatives available? It might be unsuitable where an administrator can change the system's time while the program is running. Agreed! However, it should be extremely hard to cause a clash in this way. So unless there are even safer solutions, I think this is a risk I'm willing to take. / Emil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Parallel compilation and execution?
Oops! Guess I'm going to have to refine my searching techniques. Thanks, Simon. Michael --- On Fri, 5/27/11, Simon Marlow marlo...@gmail.com wrote: From: Simon Marlow marlo...@gmail.com Subject: Re: Parallel compilation and execution? To: michael rice nowg...@yahoo.com Cc: David Virebayre dav.vire+hask...@gmail.com, Daniel Fischer daniel.is.fisc...@googlemail.com, haskell-cafe@haskell.org Date: Friday, May 27, 2011, 7:08 AM On 26/05/2011 14:32, michael rice wrote: Fair question. I copied the parallel version from: http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.html That is the User Guide for GHC 6.6, incidentally. If you're using a later version of GHC (highly recommended especially for parallel stuff), then you should look at the docs for your version. Cheers, Simon http://www.haskell.org/ghc/docs/6.6/html/users_guide/lang-parallel.htmlbut pulled the non-parallel version from a text. Michael --- On *Thu, 5/26/11, David Virebayre /dav.vire+hask...@gmail.com/* wrote: From: David Virebayre dav.vire+hask...@gmail.com Subject: Re: [Haskell-cafe] Parallel compilation and execution? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org, Daniel Fischer daniel.is.fisc...@googlemail.com Date: Thursday, May 26, 2011, 8:56 AM 2011/5/26 michael rice nowg...@yahoo.com /mc/compose?to=nowg...@yahoo.com Thank, Daniel Multiple threads are in evidence in my system monitor, but I wonder why I'm getting two different answers, one twice the other. The first is the parallel solution and the second is the non. Why do you add n1+n2+1 in the parallel program, but only n1+n2 in the non-parallel one ? Michael === {- import Control.Parallel nfib :: Int - Int nfib n | n = 1 = 1 | otherwise = par n1 (pseq n2 (n1 + n2 + 1)) where n1 = nfib (n-1) n2 = nfib (n-2) -} nfib :: Int - Int nfib n | n = 1 = 1 | otherwise = nfib (n-1) + nfib (n-2) main = do putStrLn $ show $ nfib 39 = [michael@hostname ~]$ ghc --make -threaded nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o ) Linking nfib ... [michael@hostname ~]$ ./nfib +RTS -N3 204668309 [michael@hostname ~]$ ghc --make nfib.hs [1 of 1] Compiling Main ( nfib.hs, nfib.o ) Linking nfib ... [michael@hostname ~]$ ./nfib 102334155 [michael@hostname ~]$ ___ 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 unique is Unique
There is also the UUID that guarantees uniqueness in a environment with more than one machine. http://en.wikipedia.org/wiki/Universally_unique_identifier Cheers ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How unique is Unique
2011-05-27 13:12, Simon Marlow skrev: On 27/05/2011 08:35, Emil Axelsson wrote: Hello! Lacking a proper blog, I've written some notes about Data.Unique here: http://community.haskell.org/~emax/darcs/MoreUnique/ This describes a real problem that makes Data.Unique unsuitable for implementing observable sharing. The document also proposes a solution that uses time stamps to generate symbols that are more unique. Does anyone have any comments on the proposed solution? Are there any alternatives available? This has nothing to do with Unique, you are simply using unsafePerformIO in an unsafe way. It is called unsafePerformIO for a reason :-) Right, I wasn't suggesting this is a bug in Data.Unique. It's just that I need something different. I've added a note about this on the post. Note that I am planning to wrap all this in a safe interface. So using unsafePerformIO should be fine in this case, as long as Unique symbols survive GHCi reloads. / Emil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Policy for taking over a package on Hackage
On 11-05-25 08:52 AM, Johan Tibell wrote: On Wed, May 25, 2011 at 2:01 PM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: With my wl-pprint-text package, Jason Dagit suggested to me on #haskell that it would make sense to make such a pretty-printer be class-based so that the same API could be used for String, ByteString, Text, etc. I'm a bit skeptical of using type classes to abstract over Unicode string types and byte sequence types. The only API shared by the two kind of types is that of a sequence. Things like dot , spaces, etc. don't make much sense on binary data. You must assume that the ByteString contains text in some encoding to make sense of such concepts. You don't necessarily need spaces and dot to abstract over bytestrings and Unicode string types. They both implement IsString and Monoid classes, as well as operations null, length, isPrefixOf, take, and drop. That's sufficient to implement a generic parser that works on any input type supporting these operations (see [1] for example), though there is some performance cost. I don't see why a pretty-printer should be any more difficult. [1] http://hackage.haskell.org/package/incremental-parser ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How unique is Unique
On 27/05/2011 13:40, Emil Axelsson wrote: 2011-05-27 13:12, Simon Marlow skrev: On 27/05/2011 08:35, Emil Axelsson wrote: Hello! Lacking a proper blog, I've written some notes about Data.Unique here: http://community.haskell.org/~emax/darcs/MoreUnique/ This describes a real problem that makes Data.Unique unsuitable for implementing observable sharing. The document also proposes a solution that uses time stamps to generate symbols that are more unique. Does anyone have any comments on the proposed solution? Are there any alternatives available? This has nothing to do with Unique, you are simply using unsafePerformIO in an unsafe way. It is called unsafePerformIO for a reason :-) Right, I wasn't suggesting this is a bug in Data.Unique. It's just that I need something different. I've added a note about this on the post. Note that I am planning to wrap all this in a safe interface. So using unsafePerformIO should be fine in this case, as long as Unique symbols survive GHCi reloads. Oh, I missed the bit about observable sharing, sorry. Anyway, I think the explanation for what you're seeing is that :r resets the Unique counter, because the counter is a CAF in Data.Unique and :r resets all CAFs. This wouldn't happen in a compiled program, or even using runhaskell, it's only :r that triggers resetting of CAFs. Still, to use a phrase coined by Lennart Augustsson, the ice is thin here. Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Template Haskell sometimes sees hidden constructors
Whith the three modules at the end of this email, I get some interesting results. Note that none of the constructors are exported, yet Template Haskell can see (and splice in variable occurrences of!) T, C2, W1, and W4. If you load Dump into GHCi, you get to see the Info that TH provides when you reify each of the data types. For T, T2, N1, and N4, their construct is visible in the Info even though M doesn't export it. As a consequence, you can load Unhide with no errors. Thus c = C, c2 = C2, w1 = N1, and w4 = N4, even though those constructors were not supposed to be imported. I couldn't find any mention of this on the GHC Trac for Template Haskell or for a general search of reify. * http://j.mp/l9Ztjz (Description contains reify) * http://j.mp/mprUmq (Component = Template Haskell) * Disclaimer: I didn't take the time to inspect this one http://hackage.haskell.org/trac/ghc/ticket/4946 T is isomorphic to (), T2 is like T with a phantom type argument, N1 is a newtype wrapping an Int, and N4 is like N3 with a phantom type variable. This seems too inconsistent to be an intended behavior. Am I missing something? Thanks. == M.hs == module M (T(), T1(), T2(), T3(), T4(), N1(), N3(), N4()) where data T = C data T1 = C1 Int data T2 a = C2 data T3 a = C3 a data T4 a = C4 Int newtype N1 = W1 Int newtype N3 a = W3 a newtype N4 a = W4 Int == Dump.hs == {-# LANGUAGE TemplateHaskell #-} module Dump where import Language.Haskell.TH import M dumpT, dumpT1, dumpT2, dumpT3, dumpT4, dumpN1, dumpN3, dumpN4 :: () dumpT = $(reify ''T = fail . show) dumpT1 = $(reify ''T1 = fail . show) dumpT2 = $(reify ''T2 = fail . show) dumpT3 = $(reify ''T3 = fail . show) dumpT4 = $(reify ''T4 = fail . show) dumpN1 = $(reify ''N1 = fail . show) dumpN3 = $(reify ''N3 = fail . show) dumpN4 = $(reify ''N4 = fail . show) == Unhide.hs == {-# LANGUAGE TemplateHaskell #-} module Unhide where import Language.Haskell.TH import M c :: T c = $((\(TyConI (DataD _ _ _ [NormalC n _] _)) - ConE n) `fmap` reify ''T) c2 :: T2 a c2 = $((\(TyConI (DataD _ _ _ [NormalC n _] _)) - ConE n) `fmap` reify ''T2) w1 :: Int - N1 w1 = $((\(TyConI (NewtypeD _ _ _ (NormalC n _) _)) - ConE n) `fmap` reify ''N1) w4 :: Int - N4 a w4 = $((\(TyConI (NewtypeD _ _ _ (NormalC n _) _)) - ConE n) `fmap` reify ''N4) - for convenience, this is what I get when I load Dump in ghci Dump.hs:9:11: TyConI (DataD [] M.T [] [NormalC M.C []] []) In the expression: $(reify 'T = fail . show) In an equation for `dumpT': dumpT = $(reify 'T = fail . show) Dump.hs:10:12: TyConI (DataD [] M.T1 [] [] []) In the expression: $(reify 'T1 = fail . show) In an equation for `dumpT1': dumpT1 = $(reify 'T1 = fail . show) Dump.hs:11:12: TyConI (DataD [] M.T2 [PlainTV a_1627390697] [NormalC M.C2 []] []) In the expression: $(reify 'T2 = fail . show) In an equation for `dumpT2': dumpT2 = $(reify 'T2 = fail . show) Dump.hs:12:12: TyConI (DataD [] M.T3 [PlainTV a_1627390696] [] []) In the expression: $(reify 'T3 = fail . show) In an equation for `dumpT3': dumpT3 = $(reify 'T3 = fail . show) Dump.hs:13:12: TyConI (DataD [] M.T4 [PlainTV a_1627390695] [] []) In the expression: $(reify 'T4 = fail . show) In an equation for `dumpT4': dumpT4 = $(reify 'T4 = fail . show) Dump.hs:14:12: TyConI (NewtypeD [] M.N1 [] (NormalC M.W1 [(NotStrict,ConT GHC.Types.Int)]) []) In the expression: $(reify 'N1 = fail . show) In an equation for `dumpN1': dumpN1 = $(reify 'N1 = fail . show) Dump.hs:15:12: TyConI (DataD [] M.N3 [PlainTV a_1627390694] [] []) In the expression: $(reify 'N3 = fail . show) In an equation for `dumpN3': dumpN3 = $(reify 'N3 = fail . show) Dump.hs:16:12: TyConI (NewtypeD [] M.N4 [PlainTV a_1627390693] (NormalC M.W4 [(NotStrict,ConT GHC.Types.Int)]) []) In the expression: $(reify 'N4 = fail . show) In an equation for `dumpN4': dumpN4 = $(reify 'N4 = fail . show) Failed, modules loaded: M. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] representing spreadsheets
Hi everyone, I'm hoping someone can point me in the right direction for a project I'm working on. Essentially I would like to represent a grid of data (much like a spreadsheet) in pure code. In this sense, one would need functions to operate on the concepts of rows and columns. A simple cell might be represented like this: data Cell = CellStr Text | CellInt Integer | CellDbl Double | CellEmpty The spreadsheet analogy isn't too literal as I'll be using this for data with a more regular structure. For instance, one grid might have 3 columns where every item in column one is a CellStr, every item in column two a CellStr, and every item in column 3 a CellDbl, but within a given grid there won't be surprise rows with extra columns or columns that contain some cell strings, some cell ints, etc. Representing cells in a matrix makes the most sense to me, in order to facilitate access by columns or rows or both, and I'd like to know if there's a particular matrix library that would work well with this idea. However, I'm certainly open to any other data structures that may be better suited to the task. Thanks! Eric ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] State Machine and the Abstractions
Hello, For the purposes of a simple strategy game, I'd like to build an EDSL that expresses missions. A mission could be represented as a state machine. With basic bricks such as actions (MoveTo, ShootAt...) or tests (EnemiesAround, LowHealth...), I could (ideally dynamically) build some strategic behaviors for the units. I will take the example of a patrol. Applied to a unit (or a group of units), it dictates : go from point 1 to point 2 and then go back and repeat. But when you detect an enemy near, leave the patrol path, destroy it and then resume your patrol where you left it. So if I consider my mission as a monad: data Mission = MoveTo Point | ShootAt Unit patrol = do MoveTo point1 MoveTo point2 patrol So far so good, but there, the only advantage to use a monad instead of a list of MoveTo's is the do-notation. And I lack the expression of tests. Using a GADT it could be: data Mission a where MoveTo :: Point - Mission () ShootAt :: Unit - Mission Bool -- If we have destroyed it or not EnemiesAround :: Mission [Unit] -- The enemies that are maybe in sight LowHealth :: Mission Bool -- If I should retreat ... -- (Monad Mission could be nicely expressed using Heinrich Apfelmus' * operational* package) patrol = do MoveTo point1 MoveTo point2 enemies - EnemiesAround mapM_ ShootAt enemies patrol Aaaand... here comes the trouble: the actions are done *sequentially*. My units will move and then look at enemies, they will not monitor their environment while they move. So I need a way to say: A is your action of patrolling. B is your action of surveillance. Do both in parallel, but B is preponderant, as if it successes (if enemies are there) it takes over A. So, it is as if I was running two state machines in parallel. Moreover, the last line (the recursive call to patrol) is wrong, as it will restart the patrol from the beginning, and not from where it has been left. But this could be corrected by addind a test like which point is the closest. So I thought about Arrows, as they can express sequential and parallel actions, but I don't know if it would be a right way to model the interruptions/recoveries. What do you think about it? Do you know of similar situations and of the way they've been solved? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] representing spreadsheets
Hi Eric A spreadsheet is an indexed / tabular structure which doesn't map well to Haskell's built-in way of defining data - algebraic types - which are trees via sums and products. Wolfram Kahl has a paper on modelling tables in Haskell Compositional Syntax and Semantics of Tables which might be interesting / useful: tables look like they have strong similarities to spreadsheets and the implementation is included in the appendix. Unfortunately the code is very complicated - I say this intending no criticism or judgement of Wolfram's work, just that it takes a lot of type system power to get over the representation mismatch between trees and tables. Wolfram Kahl - Compositional Syntax and Semantics of Tables http://www.cas.mcmaster.ca/sqrl/papers/sqrl15.pdf Best wishes Stephen ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] State Machine and the Abstractions
On Fri, May 27, 2011 at 2:06 PM, Yves Parès limestr...@gmail.com wrote: Hello, For the purposes of a simple strategy game, I'd like to build an EDSL that expresses missions. A mission could be represented as a state machine. With basic bricks such as actions (MoveTo, ShootAt...) or tests (EnemiesAround, LowHealth...), I could (ideally dynamically) build some strategic behaviors for the units. I will take the example of a patrol. Applied to a unit (or a group of units), it dictates : go from point 1 to point 2 and then go back and repeat. But when you detect an enemy near, leave the patrol path, destroy it and then resume your patrol where you left it. So if I consider my mission as a monad: data Mission = MoveTo Point | ShootAt Unit patrol = do MoveTo point1 MoveTo point2 patrol So far so good, but there, the only advantage to use a monad instead of a list of MoveTo's is the do-notation. And I lack the expression of tests. Using a GADT it could be: data Mission a where MoveTo :: Point - Mission () ShootAt :: Unit - Mission Bool -- If we have destroyed it or not EnemiesAround :: Mission [Unit] -- The enemies that are maybe in sight LowHealth :: Mission Bool -- If I should retreat ... -- (Monad Mission could be nicely expressed using Heinrich Apfelmus' operational package) patrol = do MoveTo point1 MoveTo point2 enemies - EnemiesAround mapM_ ShootAt enemies patrol Aaaand... here comes the trouble: the actions are done sequentially. My units will move and then look at enemies, they will not monitor their environment while they move. So I need a way to say: A is your action of patrolling. B is your action of surveillance. Do both in parallel, but B is preponderant, as if it successes (if enemies are there) it takes over A. So, it is as if I was running two state machines in parallel. Moreover, the last line (the recursive call to patrol) is wrong, as it will restart the patrol from the beginning, and not from where it has been left. But this could be corrected by addind a test like which point is the closest. Could this be expressed using a new verb in your language? data Mission a where MoveTo :: Point - Mission () ShootAt :: Unit - Mission Bool -- If we have destroyed it or not EnemiesAround :: Mission [Unit] -- The enemies that are maybe in sight LowHealth :: Mission Bool -- If I should retreat . . . Tasks :: [Mission ()] - Mission () -- goals to be achieved concurrently Options :: [Mission ()] - Mission () -- pick one of these You'd then need to analysis and interpretation tools to correctly do the right thing with it. If the game is state-machine driven, you would need sub state-machines for each possibility under 'Tasks' or 'Options'. Antoine So I thought about Arrows, as they can express sequential and parallel actions, but I don't know if it would be a right way to model the interruptions/recoveries. What do you think about it? Do you know of similar situations and of the way they've been solved? ___ 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] representing spreadsheets
Hi, Eric Rasmussen wrote: The spreadsheet analogy isn't too literal as I'll be using this for data with a more regular structure. For instance, one grid might have 3 columns where every item in column one is a CellStr, every item in column two a CellStr, and every item in column 3 a CellDbl, but within a given grid there won't be surprise rows with extra columns or columns that contain some cell strings, some cell ints, etc. Sounds more like a database than like a spreadsheet. Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] State Machine and the Abstractions
On 27 May 2011 20:06, Yves Parès limestr...@gmail.com wrote: So I thought about Arrows, as they can express sequential and parallel actions, but I don't know if it would be a right way to model the interruptions/recoveries. What do you think about it? Do you know of similar situations and of the way they've been solved? Resumption monads? Take a look at William Harrison's work especially the CellSys DSL and the models of operating systems: http://people.cs.missouri.edu/~harrisonwl/publications.html ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Enterprise Haskell -- help
On 11-05-26 12:45 PM, Srinivasan Balram wrote: (ii) Haskell Enterprise Development i.e. how to connect commercial RDBMS and use Haskell along with SQL effectively By the time we finish adding that to a future book, enterprise programmers will have already moved to the like of NoSQL and MongoDB. In fact, by the time I finish writing this message. The desired book is obsolete before its writing begins. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Enterprise Haskell -- help
We do have working and officially supported (by 10Gen) Haskell drivers for MongoDB. Just sayin' :) On Fri, May 27, 2011 at 3:45 PM, Albert Y. C. Lai tre...@vex.net wrote: On 11-05-26 12:45 PM, Srinivasan Balram wrote: (ii) Haskell Enterprise Development i.e. how to connect commercial RDBMS and use Haskell along with SQL effectively By the time we finish adding that to a future book, enterprise programmers will have already moved to the like of NoSQL and MongoDB. In fact, by the time I finish writing this message. The desired book is obsolete before its writing begins. ___ 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] representing spreadsheets
Stephen, thanks for the link! The paper was an interesting read and definitely gave me some ideas. Tillmann -- you are correct in that it's very similar to a database. I frequently go through this process: 1) Receive a flat file (various formats) of tabular data 2) Create a model of the data and a parser for the file 3) Code utilities that allow business users to filter/query/accumulate/compare the files The models are always changing, so one option would be to inspect a user-supplied definition, build a SQLite database to match, and use Haskell to feed in the data and run queries. However, I'm usually dealing with files that can easily be loaded into memory, and generally they aren't accessed with enough frequency to justify persisting them in a separate format. It's actually worked fine in the past to code a custom data type with record syntax (or sometimes just tuples) and simply build a list of them, but the challenge in taking this to a higher level is reading in a user-supplied definition, perhaps translated as 'the first column should be indexed by the string Purchase amount and contains a Double', and then performing calculations on those doubles based on further user input. I'm trying to get over bad object-oriented habits of assigning attributes at runtime and inspecting types to determine which functions can be applied to which data, and I'm not sure what concepts of functional programming better address these requirements. On Fri, May 27, 2011 at 12:33 PM, Tillmann Rendel ren...@informatik.uni-marburg.de wrote: Hi, Eric Rasmussen wrote: The spreadsheet analogy isn't too literal as I'll be using this for data with a more regular structure. For instance, one grid might have 3 columns where every item in column one is a CellStr, every item in column two a CellStr, and every item in column 3 a CellDbl, but within a given grid there won't be surprise rows with extra columns or columns that contain some cell strings, some cell ints, etc. Sounds more like a database than like a spreadsheet. Tillmann ___ 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] representing spreadsheets
On Fri, May 27, 2011 at 3:11 PM, Eric Rasmussen ericrasmus...@gmail.comwrote: Stephen, thanks for the link! The paper was an interesting read and definitely gave me some ideas. Tillmann -- you are correct in that it's very similar to a database. I frequently go through this process: 1) Receive a flat file (various formats) of tabular data 2) Create a model of the data and a parser for the file 3) Code utilities that allow business users to filter/query/accumulate/compare the files The models are always changing, so one option would be to inspect a user-supplied definition, build a SQLite database to match, and use Haskell to feed in the data and run queries. However, I'm usually dealing with files that can easily be loaded into memory, and generally they aren't accessed with enough frequency to justify persisting them in a separate format. Worth it in what terms? You're either going to have to encode the relationships yourself, or else automate the process. It's actually worked fine in the past to code a custom data type with record syntax (or sometimes just tuples) and simply build a list of them, but the challenge in taking this to a higher level is reading in a user-supplied definition, perhaps translated as 'the first column should be indexed by the string Purchase amount and contains a Double', and then performing calculations on those doubles based on further user input. I'm trying to get over bad object-oriented habits of assigning attributes at runtime and inspecting types to determine which functions can be applied to which data, and I'm not sure what concepts of functional programming better address these requirements. My intuition is to use some kind of initial algebra to create a list-like structure /for each record/ For example, with GADTs:. data Field a = Field { name :: String } data Value a = Value { value :: a } Presumably, your data definition will parse into: data RecordScheme where NoFields :: RecordScheme AddField :: Field a - RecordScheme - RecordScheme And then, given a record scheme, you can construct a Table running the appropriate queries for the scheme and Populating its Records. data Record where EndOfRecord :: Record Populate:: Value a - Record - Record type Table = [Record] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] representing spreadsheets
On Fri, May 27, 2011 at 3:11 PM, Eric Rasmussen ericrasmus...@gmail.com wrote: Stephen, thanks for the link! The paper was an interesting read and definitely gave me some ideas. Tillmann -- you are correct in that it's very similar to a database. I frequently go through this process: 1) Receive a flat file (various formats) of tabular data 2) Create a model of the data and a parser for the file 3) Code utilities that allow business users to filter/query/accumulate/compare the files The models are always changing, so one option would be to inspect a user-supplied definition, build a SQLite database to match, and use Haskell to feed in the data and run queries. However, I'm usually dealing with files that can easily be loaded into memory, and generally they aren't accessed with enough frequency to justify persisting them in a separate format. Worth it in what terms? You're either going to have to encode the relationships yourself, or else automate the process. It's actually worked fine in the past to code a custom data type with record syntax (or sometimes just tuples) and simply build a list of them, but the challenge in taking this to a higher level is reading in a user-supplied definition, perhaps translated as 'the first column should be indexed by the string Purchase amount and contains a Double', and then performing calculations on those doubles based on further user input. I'm trying to get over bad object-oriented habits of assigning attributes at runtime and inspecting types to determine which functions can be applied to which data, and I'm not sure what concepts of functional programming better address these requirements. My intuition is to use some kind of initial algebra to create a list-like structure /for each record/ For example, with GADTs:. data Field a = Field { name :: String } data Value a = Value { value :: a } Presumably, your data definition will parse into: data RecordScheme where NoFields :: RecordScheme AddField :: Field a - RecordScheme - RecordScheme And then, given a record scheme, you can construct a Table running the appropriate queries for the scheme and Populating its Records. data Record where EndOfRecord :: Record Populate:: Value a - Record - Record type Table = [Record] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] representing spreadsheets
Thanks! I think GADTs may work nicely for this project, so I'm going to start building it out. On Fri, May 27, 2011 at 4:16 PM, Alexander Solla alex.so...@gmail.comwrote: On Fri, May 27, 2011 at 3:11 PM, Eric Rasmussen ericrasmus...@gmail.comwrote: Stephen, thanks for the link! The paper was an interesting read and definitely gave me some ideas. Tillmann -- you are correct in that it's very similar to a database. I frequently go through this process: 1) Receive a flat file (various formats) of tabular data 2) Create a model of the data and a parser for the file 3) Code utilities that allow business users to filter/query/accumulate/compare the files The models are always changing, so one option would be to inspect a user-supplied definition, build a SQLite database to match, and use Haskell to feed in the data and run queries. However, I'm usually dealing with files that can easily be loaded into memory, and generally they aren't accessed with enough frequency to justify persisting them in a separate format. Worth it in what terms? You're either going to have to encode the relationships yourself, or else automate the process. It's actually worked fine in the past to code a custom data type with record syntax (or sometimes just tuples) and simply build a list of them, but the challenge in taking this to a higher level is reading in a user-supplied definition, perhaps translated as 'the first column should be indexed by the string Purchase amount and contains a Double', and then performing calculations on those doubles based on further user input. I'm trying to get over bad object-oriented habits of assigning attributes at runtime and inspecting types to determine which functions can be applied to which data, and I'm not sure what concepts of functional programming better address these requirements. My intuition is to use some kind of initial algebra to create a list-like structure /for each record/ For example, with GADTs:. data Field a = Field { name :: String } data Value a = Value { value :: a } Presumably, your data definition will parse into: data RecordScheme where NoFields :: RecordScheme AddField :: Field a - RecordScheme - RecordScheme And then, given a record scheme, you can construct a Table running the appropriate queries for the scheme and Populating its Records. data Record where EndOfRecord :: Record Populate:: Value a - Record - Record type Table = [Record] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] State Machine and the Abstractions
For one, you have a kind error. You use Mission as a Monad when it only has kind *. I don't know much of arrows, but I suggest writing the combinators you want to have with specialized types, and see where that takes you. If it happens to lead to an implementation of Arrow, yay. If it doesn't, then you at least still have something that functions. Message: 13 Date: Fri, 27 May 2011 21:06:10 +0200 From: Yves Par?slimestr...@gmail.com Subject: [Haskell-cafe] State Machine and the Abstractions To: Haskell-Cafehaskell-cafe@haskell.org Message-ID:BANLkTikVb-zhyTVR=jt03hfibakrerx...@mail.gmail.com Content-Type: text/plain; charset=iso-8859-1 Hello, For the purposes of a simple strategy game, I'd like to build an EDSL that expresses missions. A mission could be represented as a state machine. With basic bricks such as actions (MoveTo, ShootAt...) or tests (EnemiesAround, LowHealth...), I could (ideally dynamically) build some strategic behaviors for the units. I will take the example of a patrol. Applied to a unit (or a group of units), it dictates : go from point 1 to point 2 and then go back and repeat. But when you detect an enemy near, leave the patrol path, destroy it and then resume your patrol where you left it. So if I consider my mission as a monad: data Mission = MoveTo Point | ShootAt Unit patrol = do MoveTo point1 MoveTo point2 patrol So far so good, but there, the only advantage to use a monad instead of a list of MoveTo's is the do-notation. And I lack the expression of tests. Using a GADT it could be: data Mission a where MoveTo :: Point - Mission () ShootAt :: Unit - Mission Bool -- If we have destroyed it or not EnemiesAround :: Mission [Unit] -- The enemies that are maybe in sight LowHealth :: Mission Bool -- If I should retreat ... -- (Monad Mission could be nicely expressed using Heinrich Apfelmus' * operational* package) patrol = do MoveTo point1 MoveTo point2 enemies- EnemiesAround mapM_ ShootAt enemies patrol Aaaand... here comes the trouble: the actions are done *sequentially*. My units will move and then look at enemies, they will not monitor their environment while they move. So I need a way to say: A is your action of patrolling. B is your action of surveillance. Do both in parallel, but B is preponderant, as if it successes (if enemies are there) it takes over A. So, it is as if I was running two state machines in parallel. Moreover, the last line (the recursive call to patrol) is wrong, as it will restart the patrol from the beginning, and not from where it has been left. But this could be corrected by addind a test like which point is the closest. So I thought about Arrows, as they can express sequential and parallel actions, but I don't know if it would be a right way to model the interruptions/recoveries. What do you think about it? Do you know of similar situations and of the way they've been solved? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Erlang's module discussion
Hi All, I sure love Hackage, but there's a very interesting discussion going on, on the Erlang mailing list, about completely restructuring the module-model. Before you dismiss it as crazy, know that the topic was brought up by Joe Armstrong, one of the creators of the language. Here's the archive: http://erlang.org/pipermail/erlang-questions/2011-May/058769.html Food for thought... Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Erlang's module discussion
On Fri, May 27, 2011 at 23:10, Tom Murphy amin...@gmail.com wrote: I sure love Hackage, but there's a very interesting discussion going on, on the Erlang mailing list, about completely restructuring the module-model. Sounds like one of those ideas that looks really neat on paper but in the real world runs up against the fact that we're absolutely *abysmal* at managing that much metadata, and our programs to do so mostly reflect our inabilities. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe