Re: [Haskell-cafe] Using lenses
Hi, In a game I made recently, I had to load OBJ formatted models into an OpenGL-friendly format. To do that, I'd parse the .obj, into a simple ADT, and build the model into a vector. Here's where lens comes in: we want to build separate vectors for the vertices, normals, UVs and faces indices. lens made that very easy, in conjunction with the state monad. Unlike normal record fields, you can actually pass around lenses freely. data ModelBuilder = ModelBuilder { _mbVertices, _mbNormals, _mbUvs :: [Vector Float], ... } makeFields ''ModelBuilder addTo label a = label %= (++ Vector.fromList a) which would be used like: case objCommand of V x y z - addTo vertices [x,y,z] VN x y z - addTo normals [x,y,z] VT x y z - addTo uvs [x,y,z] ... I hope to actually release the game that uses this soon -- it's one of the very few 'complete' 3D games written in Haskell -- when I have the time, which will probably be around november. - Mike On Thu, Oct 3, 2013 at 6:07 PM, Simon Peyton-Jones simo...@microsoft.comwrote: (I sent this to ‘libraries’ but Kim-Ee suggested adding Café, where so many smart people hang out.) ** ** Friends ** ** Some of you will know that I’ve promised to give a talk about Edward’s lens library http://hackage.haskell.org/package/lens at the Haskell Exchange http://skillsmatter.com/event/scala/haskell-exchange in London next Wednesday (9th). I did this to give everyone (including me) a break from GHC hackery, and also to force me to learn about this lens voodoo that everyone is twittering about. Edward generously gave me quite a bit of one-to-one attention last week (my hair is still standing on end), but this message is to ask your help too. *Specifically, I’d like to give some compelling use-cases*. If you are using the lens library yourself, could you spare a few minutes to tell me how you are using it? I expect to cover Lens and Traversal but not Prism. ** ** The use-case everyone starts with is nested records, but I’d like to go beyond that. The next levels seem to be: **· **Lenses as views of data that isn’t “really there” e.g. regarding a record with rectangular coordinates as having polar coordinates too. **· **Lenses and Traversals that focus on elements of finite maps (Control.Lens.At) ** ** What else? I’m sure you are using them in all sorts of cool ways that I would never think of, and I’d love to know. ** ** Please don’t tell me anything secret! To give everyone the benefit I may just concatenate all the replies and send to you all, so please say if you don’t want me to do that with yours. ** ** And don’t burn too many cycles on this...I don’t want to waste your time, and I can always get back to you if I can’t understand what you say. Sooner is better than later...Weds is coming. ** ** Simon “Edward’s prophet” PJ ** ** ___ 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] One-element tuple
It seems to me that this is Identity given a different name. A bonus of using Identity is that it won't introduce any new packages to the majority of installations. On 20/08/2013 1:17 PM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: On 20 August 2013 11:07, AntC anthony_clay...@clear.net.nz wrote: Daniel F difrumin at gmail.com writes: Can you please elaborate why this inconsistency is annoying and what's the use of OneTuple? Genuine question, Hi Daniel, the main annoyance is the verbosity (of using a data type and constructor), and that it no longer looks like a tuple. The inconsistency is because a one-element tuple is just as cromulent as a n-element, or a zero-element. (And that a one-element tuple is a distinct type from the element on its own/un-tupled.) Why is it as cromulent (especially as I'm not so sure we could really consider () to be merely a zero-element tuple)? I can see what you're trying to do here, but for general usage isn't a single element tuple isomorphic to just that element (which is what newtypes are for if you need that distinction)? So if I have instances (as I do) like: instance C (a, b) ... instance C () ... I can't usefully put either of these next two, because they're equiv to the third: instance C (( a )) ... instance C ( a ) ... instance C a ... -- overlaps every instance Similarly for patterns and expressions, the so-called superfluous parens are just stripped away, so equivalent to the bare term. The use of OneTuple is that it comes with all Prelude instances pre- declared (just like all other tuple constructors). I don't see that it has an advantage over declaring your own data type(?) I'd also be interested to know who is using it, and why. As far as I'm aware, it's just a joke package, but two packages dealing with tuples seem to use it: http://packdeps.haskellers.com/reverse/OneTuple What I'm doing is building Type-Indexed Tuples [1] mentioned in HList [2], as an approach to extensible records [3], on the model of Trex [4] -- all of which acknowledge one-element records/rows/tuples. And then I'm using the tuples as a platform for relational algebra [5] with natural Join (and ideas from Tropashko's 'Relational Lattice' [6]). Is there anybody using OneTuple 'in anger'? AntC [1] M. Shields and E.Meijer. Type-indexed rows. In Proceedings of the 28th ACM SIGPLAN-SIGACT symposium on Principles of Programming Languages, pages 261–275. ACMPress, 2001. [2] http://hackage.haskell.org/package/HList [3] http://www.haskell.org/haskellwiki/Extensible_record [4] http://web.cecs.pdx.edu/~mpj/pubs/polyrec.html [5] http://en.wikipedia.org/wiki/Relational_algebra#Natural_join_ [6] http://vadimtropashko.wordpress.com/relational-lattice/ On Fri, Aug 16, 2013 at 5:35 AM, AntC anthony_clayden at clear.net.nz wrote: There's an annoying inconsistency: (CustId 47, CustName Fred, Gender Male) -- threeple (CustId 47, CustName Fred)-- twople -- (CustId 47)-- oneple not! () -- nople ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com http://IvanMiljenovic.wordpress.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] Array, Vector, Bytestring
On 05/06/13 02:49, silvio wrote: Just to clarify for those on the sidelines, the issue is duplication of implementation details, rather than duplication of functionality? Well to me, that is not the main issue. The main issue is that you have to study all of them and depending on which libraries you want to use have to convert between them, which could be expensive and is definitely annoying. I made a few simple benchmarks comparing the three libraries you can find the code attached. this is compiled with -O2 # simple sum of 100 Word8 elements Unboxed Vector 1.114060 ms Storable Vector 795.1207 us Primitive Vector 1.116145 ms ByteString 9.076256 ms array library has no fold or sum function # simple sum of 100 more or less randomly chosen elements Unboxed Vector (unsafe)33.74364 ms Storable Vector (unsafe) 50.27273 ms Storable Vector (safe) 67.01634 ms Primitive Vector (unsafe) 56.29919 ms ByteString (unsafe)19.29611 ms ByteString (safe) 18.29065 ms UArray (safe) 46.88719 ms unsafe does not exist for array So Unboxed can be better than Storable but doesn't need to be. Also, which implementation is faster depends very much on the problem at hand. And array is just missing half the needed features. Silvio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe array does provide folding functions, found in its Foldable and Traversable instances. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Array, Vector, Bytestring
On 05/06/13 07:01, silvio wrote: array does provide folding functions, found in its Foldable and Traversable instances. Where can I find this? I can neither in the array package nor with google nor with hoogle. Silvio ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Data.Foldable and Data.Traversable, if you hoogle Foldable or Traversable you'll find their modules' docs. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Remove redundancy with Template Haskell
argh, always forget to reply to all It's possible, just somewhat painful because TH /requires/ you to build an AST -- you can't just return a string representing what you want to splice in. Here's one using haskell-src-meta: {-# LANGUAGE TemplateHaskell #-} import Language.Haskell.TH import Language.Haskell.Meta call :: Name - String - Q Exp call name exp' = case parseExp exp' of Right expr - let fun = [| name |] str = stringE exp' in [| $fun $(return expr) $str |] _ - error Invalid expression. This can be then used to make a QuasiQuoter: call' :: QuasiQuoter call' = QuasiQuoter { quoteExp = call 'functionYouWantHere } On Fri, Mar 29, 2013 at 8:40 AM, Corentin Dupont corentin.dup...@gmail.com wrote: Thanks Daniel, that's very simple! Realizing this in TH seems be impossible, is it right? On Wed, Mar 27, 2013 at 10:33 PM, Daniel Trstenjak daniel.trsten...@gmail.com wrote: Hi Corentin, On Wed, Mar 27, 2013 at 09:13:41PM +0100, Corentin Dupont wrote: I have a function that looks like this: call :: SomeFunction - String - SomeState The string is actually the representation of the function passed in parameter. It is stored in the state for documentation. So a call looks like that: call (\a - putStrLn a) \a - putStrLn a There is a clear redundancy here, how could I remove it with Template Haskell? I cannot figure out... You can even use cpp to get something like: #define CALL(func) call (func) #func CALL(\a - a + 1) = call (\a - a + 1) \a - a + 1 Greetings, Daniel ___ 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] GHC for mobile devices?
I would be so very happy to be able to program Haskell Android programs. I think the steps we'd need are to 1. Port GHC to ARM (done already?) and 2. Create a JVM calling convention for GHC (using JNI? I have no idea). Short of actually making a new calling convention for the JVM, maybe we could use the JNI to create a thin C wrapper that has the code we want to import normally. Unfortunately I have no idea of where to start and very little experience with Android other than firing up Eclipse, playing around with simple applications and being very dissatisfied. On Sat, Nov 10, 2012 at 4:32 PM, Andrew Pennebaker andrew.penneba...@gmail.com wrote: Awesome! Jeffrey Scofield has ported OCaml to iOShttp://psellos.com/ocaml/compile-to-iossim.html, so there's also experience there. On Fri, Nov 9, 2012 at 11:46 PM, Kristopher Micinski krismicin...@gmail.com wrote: If you have interest in doing this, I have quite a bit of experience in Android hacking at the system level and above and would be glad to talk about what might need to happen. (Though I don't know the GHC internals / toolchain so well.) One potential choice is Scala, though from my limited experience that's a very rough imitation of the uses for Haskell. (Though, obviously it works mostly out of the box because of the JVM compiler target..) http://www.haskell.org/haskellwiki/Android I've been writing up some thoughts on the Android activity lifecycle already interpreted with respect to FP, apps are quite functional already for a variety of reasons. kris On Fri, Nov 9, 2012 at 8:51 PM, Andrew Pennebaker andrew.penneba...@gmail.com wrote: I'd love to use Haskell directly for making mobiles apps. How can we make this happen, porting GHC to Android, iOS, and Windows Phone? -- Cheers, Andrew Pennebaker www.yellosoft.us ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Cheers, Andrew Pennebaker www.yellosoft.us ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to waitForProcess?
You might have to use hGetContents, then waitForProcess, and then terminateProcess -- you can then check if the process is indeed terminated using getProcessExitCode. On Wed, Sep 5, 2012 at 1:45 PM, Magicloud Magiclouds magicloud.magiclo...@gmail.com wrote: Hi, I have code like this and it leaves lots of zombies of flow-export. Then I add waitForProcess Well I do not know where to put it. Before or after 'hGetContents' both make the program hung. exportCSV :: FilePath - IO [String] exportCSV file = do csv_ - withBinaryFile file ReadMode $ \i - do (_, Just o, _, h) - createProcess $ CreateProcess (RawCommand /usr/bin/flow-export [-f2]) Nothing Nothing (UseHandle i) CreatePipe Inherit True False hGetContents o return $ tail $ lines csv_ -- 竹密岂妨流水过 山高哪阻野云飞 And for G+, please use magiclouds#gmail.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] Template Haskell antiquotation in user-defined quasiquoters
(oops, sorry, didn't do reply to all) I use haskell-src-meta in QuasiText (on hackage) also. It would certainly be nice to have native anti-quotations, but for now haskell-src-meta does a very good job. Mike On Sat, May 26, 2012 at 8:31 AM, Geoffrey Mainland mainl...@apeiron.netwrote: On 05/25/2012 21:46, Antoine Latter wrote: On Fri, May 25, 2012 at 2:51 PM, Sam Lindley sam.lind...@ed.ac.uk wrote: Template Haskell supports antiquotation for built-in quasiquotes, e.g.: [| \x - x + $([|3 * 4|]) |] However, as far as I can tell, there is no way of supporting antiquotation in user-defined quasiquoters, because the only way to specify a new quasiquoter is through a quoteExp function of type String - Q Exp. Of course, it is perfectly possible to write a parser for some fragment of Haskell inside your quoteExp function, but that seems crazy given that Template Haskell or rather GHC already implements a parser for the whole language. I know about Language.Haskell.Exts.Parser in haskell-src-exts, which provides parseExp :: String - ParseResult Exp, but that Exp is a different type to the one provided by Template Haskell. http://hackage.haskell.org/packages/archive/haskell-src-exts/1.9.0/doc/html/Language-Haskell-Exts-Syntax.html#t:Exp I'm also aware of Dominic Orchard's syntax-trees package, which supports converting between the two representations using a cunning hack that pretty-prints the haskell-src-exts representation to a string and uses Template Haskell to parse it back. Is there a saner way of simulating antiquotation in user-defined quasiquoters? Have you looked at: http://hackage.haskell.org/package/haskell-src-exts-qq http://hackage.haskell.org/package/haskell-src-meta The might help you pull something together. Antoine Sam I use haskell-src-meta in language-c-quote (also on hackage) to support antiquotation and heartily endorse it. I have not used haskell-src-exts-qq. Geoff ___ 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