Re: [Haskell-cafe] A question regarding reading CPP definitions from a C header

2013-10-07 Thread Ömer Sinan Ağacan
Carl, thank you very much. This is exactly what I was looking for, and it solved my problem in 5 minutes. What's awesome is that when Cabal finds a .hsc file it automatically calls this tool. Great. Thanks again. --- Ömer Sinan Ağacan http://osa1.net 2013/10/8 Carl Howells : > Have you looked

Re: [Haskell-cafe] A question regarding reading CPP definitions from a C header

2013-10-07 Thread Carl Howells
Have you looked into using hsc2hs? If I understand your problem, it's designed exactly to solve it. -- Carl On Mon, Oct 7, 2013 at 12:20 PM, Ömer Sinan Ağacan wrote: > Thanks for your answer, looks like this is my only option to do this. > > Can you provide some information about what does par

Re: [Haskell-cafe] A question regarding reading CPP definitions from a C header

2013-10-07 Thread Ömer Sinan Ağacan
Thanks for your answer, looks like this is my only option to do this. Can you provide some information about what does parameters of runCpphsReturningSymTab stands for? I made several attempts but couldn't get any useful return value. For example, I have no idea what does third parameter does. Al

Re: [Haskell-cafe] A question regarding reading CPP definitions from a C header

2013-10-07 Thread Malcolm Wallace
If you use cpphs as a library, there is an API called runCpphsReturningSymTab. Thence you can throw away the actual pre-preprocessed result text, keep only the symbol table, and lookup whatever macros you wish to find their values. I suggest you make this into a little code-generator, to produ

[Haskell-cafe] A question regarding reading CPP definitions from a C header

2013-10-05 Thread Ömer Sinan Ağacan
Hi all, Let's say I want to #include a C header file in my Haskell library just to read some macro definitions. The C header file also contains some C code. Is there a way to load only macro definitions and not C code in #include declarations in Haskell? What I'm trying to do is I'm linking my li

Re: [Haskell-cafe] A question about laziness and performance in document serialization.

2013-08-22 Thread Roman Cheplyaka
* Kyle Hanson [2013-08-20 18:23:48-0700] > So I am not entirely clear on how to optimize for performance for lazy > bytestrings. > > Currently I have a (Lazy) Map that contains large BSON values (more than > 1mb when serialized each). I can serialize BSON documents to Lazy > ByteStrings using Dat

[Haskell-cafe] A question about laziness and performance in document serialization.

2013-08-20 Thread Kyle Hanson
So I am not entirely clear on how to optimize for performance for lazy bytestrings. Currently I have a (Lazy) Map that contains large BSON values (more than 1mb when serialized each). I can serialize BSON documents to Lazy ByteStrings using Data.Binary.runPut. I then write this bytestring to a soc

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-31 Thread Tommy Thorn
And if you are, you may be interested in https://github.com/tommythorn/Reduceron The underlying topic is a fascinating one. The fact that people ignore is that silicon cycle time improvements have been fairly modest - perhaps 2-3 orders of magnitude and we have long been at the point where wire de

Re: [Haskell-cafe] A question about data declaration

2013-03-23 Thread Evan Laforge
> Brent, my use case is not particularly complicated. I am trying to model the > pdf spec - which says that pdf contains Objects that could of of types > Number, String, Name, Array and Dictionary - while array is list of objects, > the Disctionary is a list of tuples (Name, Object) not (Object, Ob

Re: [Haskell-cafe] A question about data declaration

2013-03-23 Thread Doug Burke
On Mar 22, 2013 2:58 AM, "C K Kashyap" wrote: > > Thanks Eric and Brent, > > Even with GADT, it appears that I'd need extra data definitions. I'll go without GADT then ... > > Brent, my use case is not particularly complicated. I am trying to model the pdf spec - which says that pdf contains Objec

Re: [Haskell-cafe] A question about data declaration

2013-03-21 Thread C K Kashyap
Thanks Eric and Brent, Even with GADT, it appears that I'd need extra data definitions. I'll go without GADT then ... Brent, my use case is not particularly complicated. I am trying to model the pdf spec - which says that pdf contains Objects that could of of types Number, String, Name, Array and

Re: [Haskell-cafe] A question about data declaration

2013-03-21 Thread Brent Yorgey
On Thu, Mar 21, 2013 at 06:18:46PM +0530, C K Kashyap wrote: > Hi, > > I have a situation where I need to define a data type T such that > > data T = C1 Int | C2 Char | C3 T > > However, I want to enforce a constraint that C3 only allows (C2 Char) and > not (C1 Int). That is If C3 should only b

Re: [Haskell-cafe] A question about data declaration

2013-03-21 Thread Erik Hesselink
You could use a GADT: {-# LANGUAGE GADTs #-} data T a where C1 :: Int -> T Int C2 :: Char -> T Char C3 :: T Char -> T Char This will allow you to put a C3 in a C3. If you want to prevent that, just invent some other index, something like: {-# LANGUAGE GADTs, EmptyDataDecls #-} data Yes d

[Haskell-cafe] A question about data declaration

2013-03-21 Thread C K Kashyap
Hi, I have a situation where I need to define a data type T such that data T = C1 Int | C2 Char | C3 T However, I want to enforce a constraint that C3 only allows (C2 Char) and not (C1 Int). That is x = C3 (C1 10) -- should not compile - but my above definition will let it compile I was think

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-19 Thread Simon Farnsworth
OWP wrote: > Ironically, you made an interesting point on how Moore's Law created > the on chip "real estate" that made specialized machines possible. As > transistor sizing shrinks and die sizes increase, more and more real > estate should now be available for usage. Oddly, what destroyed > spe

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-18 Thread OWP
Ironically, you made an interesting point on how Moore's Law created the on chip "real estate" that made specialized machines possible. As transistor sizing shrinks and die sizes increase, more and more real estate should now be available for usage. Oddly, what destroyed specialized machines in t

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-18 Thread Richard A. O'Keefe
On 19/03/2013, at 9:31 AM, OWP wrote: > If I may ask, I'm not quite sure what O(2^n) and O(1) are? Check any data structures and algorithms textbook. Reverting to the original topic, THIS is the age of specialised machines. A lot of the chips out there are not just a CPU but a SoC (System on a

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-18 Thread Brandon Allbery
On Mon, Mar 18, 2013 at 4:31 PM, OWP wrote: > Let me rephrase that, of course they will survive politically. People > built these tools and if built, they will be use but will they survive > efficiently? In the future, if a particular specialized architecture > is somewhat better than the rest

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-18 Thread Gwern Branwen
On Mon, Mar 18, 2013 at 4:31 PM, OWP wrote: > If I may ask, I'm not quite sure what O(2^n) and O(1) are? Just a metaphor using algorithmic complexity, is all. > I'm curious, were not all these built on the foundation of Moore's > Law? Everything Vigoda lists has Moore's Law in mind. If Moore's

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-18 Thread OWP
If I may ask, I'm not quite sure what O(2^n) and O(1) are? "Besides Moore's Law, digital computing also benefits from mature tools and expertise for optimizing performance at all levels of the system: process technology, fundamental circuits, layout and algorithms. Many engineers are simultaneousl

Re: [Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-17 Thread Gwern Branwen
On Sun, Mar 17, 2013 at 5:56 PM, OWP wrote: > These "stock architectures", were they really so good that they out > performed the specialized ones on it's own merits or was this mainly due to > Moore's Law on transistors? In other words, suppose we separate Moore's Law > from the stock architectu

[Haskell-cafe] Specialized Computer Architecture - A Question

2013-03-17 Thread OWP
Hi, I was reading the paper "A History of Haskell: being lazy with class" ( http://www.haskell.org/haskellwiki/History_of_Haskel) and came on a section (I 2.1) which briefly explained the work people did on making non-von Neumann architectures. It concluded by saying "Much (but not all) of this

[Haskell-cafe] A question about "An introduction to Category theory in four easy movements"

2013-02-03 Thread Jan Stolarek
Hi all, I was thinking about reading "An introduction to Category theory in four easy movements" available online at http://www.cs.man.ac.uk/~hsimmons/BOOKS/books.html I noticed however that these notes were published as a book. Looking at the table of contents at Amazon, it seems that organi

Re: [Haskell-cafe] A Question about withFile

2012-07-25 Thread Chris Dornan
Bin Shi Sent: 25 July 2012 11:00 To: haskell-cafe@haskell.org Subject: [Haskell-cafe] A Question about withFile Hello, I wrote a simple test program as main = do withFile "a.txt" ReadMode (\h -> do c <- hGetContents h putStrLn c) then I got my expected results: I&#

[Haskell-cafe] A Question about withFile

2012-07-25 Thread Bin Shi
Hello, I wrote a simple test program as main = do withFile "a.txt" ReadMode (\h -> do c <- hGetContents h putStrLn c) then I got my expected results: I'm a.txt but if I changed to main = do c <- withFile "a.txt" ReadMode hGetContents putStrLn c I got just a emp

Re: [Haskell-cafe] A question about causality in FRP

2011-10-15 Thread Alan Jeffrey
One more thing... The function: return :: a -> Beh a return x t = x fails to be causal when a is itself a behaviour, since it specializes to (after a bit of eta-conversion): return :: Beh a -> Beh (Beh a) return b t u = b u which isn't causal. This rules out return, which in turn mea

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread Alan Jeffrey
I should add that I have a pragmatic reason for asking about causality, which is that over at https://github.com/agda/agda-frp-js I have an implementation of FRP for Agda running in the browser using an Agda-to-JS back end I wrote. In that model, I can see how to implement deep causality, but

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread David Barbour
On Fri, Oct 14, 2011 at 7:27 AM, Alan Jeffrey wrote: > On 10/13/2011 10:43 PM, David Barbour wrote: > >> On Thu, Oct 13, 2011 at 7:54 AM, Alan Jeffrey > > wrote: >> The `problem` such as it exists: you will be unable to causally >> construct the argument toith the

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread David Barbour
On Fri, Oct 14, 2011 at 3:07 AM, Ertugrul Soeylemez wrote: > It's not about the laws, it's about losing state. > I think you should not accumulate state; the abstraction gives me a fresh arrow each instant, conceptually and pragmatically. But it would not be difficult to create an abstraction sp

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread Alan Jeffrey
On 10/13/2011 10:43 PM, David Barbour wrote: On Thu, Oct 13, 2011 at 7:54 AM, Alan Jeffrey mailto:ajeff...@bell-labs.com>> wrote: The `problem` such as it exists: you will be unable to causally construct the argument toith the `weird` function, except by modeling a nested/simulated world (i.e. mo

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread Heinrich Apfelmus
David Barbour wrote: Alan Jeffrey wrote: A function (f : Beh A -> Beh B) is causal whenever it respects =t, i.e. (forall t . a =t b => f a =t f b). Yes. Function outputs only depend on the past values of the input function. Your solutions for double and weird are accurate. Double is lifting

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread Ertugrul Soeylemez
David Barbour wrote: > > The usual model for arrowized FRP is based on this type: > > > >newtype Auto a b = Auto (a -> (b, Auto a b)) > > > > I would be very interested in how you would write an ArrowApply > > instance for such a type. So far my conclusion is: It's > > impossible. > > Inter

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread David Barbour
On Fri, Oct 14, 2011 at 1:31 AM, Ertugrul Soeylemez wrote: > David Barbour wrote: > > > If you want first-class behaviors or behavior transformers, those will > > need a different abstraction than 'nested' behaviors. Nested != First > > Class. You'd have special functions to lift a first-class

Re: [Haskell-cafe] A question about causality in FRP

2011-10-14 Thread Ertugrul Soeylemez
David Barbour wrote: > If you want first-class behaviors or behavior transformers, those will > need a different abstraction than 'nested' behaviors. Nested != First > Class. You'd have special functions to lift a first-class behavior as > an argument (e.g. add a phantom type to prohibit non-cau

Re: [Haskell-cafe] A question about causality in FRP

2011-10-13 Thread David Barbour
On Thu, Oct 13, 2011 at 7:54 AM, Alan Jeffrey wrote: > A function (f : Beh A -> Beh B) is causal whenever it respects =t, i.e. > (forall t . a =t b => f a =t f b). > Yes. Function outputs only depend on the past values of the input function. Your solutions for double and weird are accurate. Doub

[Haskell-cafe] A question about causality in FRP

2011-10-13 Thread Alan Jeffrey
Hi everyone, Not sure this is the right venue, as this is a question about the semantics of FRP rather than Haskell... I have a question about the definition of "causality" for stream functions. A quick recap... Given a totally ordered set T (of times), the type of behaviour

Re: [Haskell-cafe] A question about monad laws

2011-01-20 Thread Henning Thielemann
C K Kashyap schrieb: > Hi, > I am trying to get a better understanding of the "monad laws" - right > now, it seems too obvious > and pointless. I had similar feelings about identity function when I > first saw it but understood its use > when I saw it in action. > Could someone please help me get a

Re: [Haskell-cafe] A question about monad based on http://en.wikipedia.org/wiki/Monad_(category_theory)

2011-01-20 Thread Gregg Reynolds
On Mon, Jan 17, 2011 at 9:46 PM, C K Kashyap wrote: > > I am not able to fully understand how those diagrams translate to haskell - > I can guess that T^2 -> T referes to things like concat operation but not > able to relate it to bind. > > I found it useful to work out the correspondence between

Re: [Haskell-cafe] A question about monad based on http://en.wikipedia.org/wiki/Monad_(category_theory)

2011-01-19 Thread wren ng thornton
On 1/17/11 10:46 PM, C K Kashyap wrote: Hi, I was going through http://en.wikipedia.org/wiki/Monad_(category_theory) - under Formal Definition I notice that monad is a Functor T:C -> C My question is - when we think of Maybe as a functor T:C -> C should we think that C here refers to Hake

Re: [Haskell-cafe] A question about monad laws

2011-01-18 Thread C K Kashyap
Thank you very much Sebastian, The example did make it clearer. I can see now that monads obeying the laws is what lets the 'do' notation work on all monads in a consistent manner. Regards, Kashyap ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] A question about monad based on http://en.wikipedia.org/wiki/Monad_(category_theory)

2011-01-18 Thread C K Kashyap
Thank you very much Brent, > > My question is - when we think of Maybe as a functor T:C -> C should > we > > think that C here refers to Hakell types? As in, > > (Int and Maybe Int are objects in C) and (Int -> Int and Maybe Int -> > Maybe > > Int are arrows in C) and T is an arrow between t

Re: [Haskell-cafe] A question about monad laws

2011-01-18 Thread Sebastian Fischer
Hi Kashyap, > Could someone please help me get a better understanding of the necessity of > monads complying with these laws? Maybe it helps to write them in do-notation. Once written like this, it becomes clear(er?) that do-notation would be much less intuitive if the laws would not hold: Left

Re: [Haskell-cafe] A question about monad based on http://en.wikipedia.org/wiki/Monad_(category_theory)

2011-01-18 Thread Brent Yorgey
On Tue, Jan 18, 2011 at 09:16:06AM +0530, C K Kashyap wrote: > Hi, > I was going through http://en.wikipedia.org/wiki/Monad_(category_theory) - > under Formal Definition I notice that monad is a Functor T:C -> C > > My question is - when we think of Maybe as a functor T:C -> C should we > thi

[Haskell-cafe] A question about monad based on http://en.wikipedia.org/wiki/Monad_(category_theory)

2011-01-17 Thread C K Kashyap
Hi, I was going through http://en.wikipedia.org/wiki/Monad_(category_theory) - under Formal Definition I notice that monad is a Functor T:C -> C My question is - when we think of Maybe as a functor T:C -> C should we think that C here refers to Hakell types? As in, (Int and Maybe Int are obje

Re: [Haskell-cafe] A question about monad laws

2011-01-17 Thread C K Kashyap
Thanks Tobias, Without the associativity law, it would be very hard to determine the > current state of the monad. > Since the compiler, on "desugaring" do-blocks, will insert brackets, there > is no guarantee that the results are the same as for the brace-less and > sugar-free version of the code

Re: [Haskell-cafe] A question about monad laws

2011-01-17 Thread Tobias Schoofs
Perhaps this might help: I wrote a kind of logger monad that inserted messages with a context. Behind was an algebraic data type, let's say "LoggerState". The API provided methods to add a message like this: addError :: String -> Logger () addError "Fatal error occurred" addWarning "Some warnin

[Haskell-cafe] A question about monad laws

2011-01-16 Thread C K Kashyap
Hi, I am trying to get a better understanding of the "monad laws" - right now, it seems too obvious and pointless. I had similar feelings about identity function when I first saw it but understood its use when I saw it in action. Could someone please help me get a better understanding of the necess

Re: [Haskell-cafe] A question regarding cmdargs package

2010-12-31 Thread Sönke Hahn
On Thursday, December 30, 2010 06:50:32 pm Neil Mitchell wrote: > Hi Sönke, > > I've just released cmdargs-0.6.6 which supports helpArgs [groupname > "Something"] That was fast! Thanks a lot, works like a charm. Thanks, Sönke ___ Haskell-Cafe mailing

Re: [Haskell-cafe] A question regarding cmdargs package

2010-12-30 Thread Neil Mitchell
Hi Sönke, I've just released cmdargs-0.6.6 which supports helpArgs [groupname "Something"] Thanks, Neil On Thu, Dec 30, 2010 at 5:09 PM, Neil Mitchell wrote: > Hi Sönke, > > helpArg [groupname "Something"] should work, but it sounds like it > doesn't. I've raised a bug: > http://code.google.com

Re: [Haskell-cafe] A question regarding cmdargs package

2010-12-30 Thread Neil Mitchell
Hi Sönke, helpArg [groupname "Something"] should work, but it sounds like it doesn't. I've raised a bug: http://code.google.com/p/ndmitchell/issues/detail?id=392 I'll probably have this fixed in about a week. Thanks, Neil On Thu, Dec 30, 2010 at 4:05 PM, Sönke Hahn wrote: >> That i18n is a fan

Re: [Haskell-cafe] A question regarding cmdargs package

2010-12-30 Thread Sönke Hahn
> That i18n is a fantastic argument - and one that really means cmdargs > has no choice but to support all the attributes on help/version. Is it possible to change the "groupname" for the implicit "help" and "version" options? I have defined some options with groupname "development flags", but I

Re: [Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-13 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 10/13/10 06:07 , Henning Thielemann wrote: > Ben Franksen schrieb: >> I wanted to create a clone of an existing program that had no help option >> and instead gave the help output if it saw an invalid option. > > I find it very annoying if a progra

Re: [Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-13 Thread Henning Thielemann
Ben Franksen schrieb: > Neil Mitchell wrote: This makes me curious. What's the use case where you want to allow the user to pass arguments on the command line, but you don't want that user to be able to use '--help' to find out what arguments may be passed? > > I wanted to cre

Re: [Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-12 Thread Neil Mitchell
> The point here was not so much removing --help, but rather that I want to > have control over the 'standard' options (help,version,verbosity) in the > same way as for the rest. My program might not have a version, so why > offer --version? Or maybe I want a different name for it because the -V is

[Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-12 Thread Ben Franksen
Joachim Breitner wrote: > Am Dienstag, den 12.10.2010, 16:42 +1100 schrieb Ivan Lazar Miljenovic: >> On 12 October 2010 16:32, Magnus Therning wrote: >> > >> > This makes me curious. What's the use case where you want to allow the >> > user to pass arguments on the command line, but you don't wan

[Haskell-cafe] Re: Re: A question regarding cmdargs package

2010-10-12 Thread Ben Franksen
Neil Mitchell wrote: >>> This makes me curious.  What's the use case where you want to allow the >>> user to pass arguments on the command line, but you don't want that user >>> to be able >>> to use '--help' to find out what arguments may be passed? I wanted to create a clone of an existing progr

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-12 Thread Joachim Breitner
Hi, Am Dienstag, den 12.10.2010, 16:42 +1100 schrieb Ivan Lazar Miljenovic: > On 12 October 2010 16:32, Magnus Therning wrote: > > > > This makes me curious. What's the use case where you want to allow the user > > to pass arguments on the command line, but you don't want that user to > > be abl

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-12 Thread Neil Mitchell
>> This makes me curious.  What's the use case where you want to allow the user >> to pass arguments on the command line, but you don't want that user to >> be able >> to use '--help' to find out what arguments may be passed? > > When you don't want to bother defining the help options/descriptions?

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-11 Thread Ivan Lazar Miljenovic
On 12 October 2010 16:32, Magnus Therning wrote: > > This makes me curious.  What's the use case where you want to allow the user > to pass arguments on the command line, but you don't want that user to > be able > to use '--help' to find out what arguments may be passed? When you don't want to b

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-11 Thread Magnus Therning
On 11/10/10 22:04, Neil Mitchell wrote: > Hi Ben, > How can I disable the standard arguments 'help' and 'version'? > > In general I suggest you email the author of the cmdargs package > directly, as well as cc'ing the mailing list (otherwise the author > might miss this message, as I did!) > >

Re: [Haskell-cafe] Re: A question regarding cmdargs package

2010-10-11 Thread Neil Mitchell
Hi Ben, >>> How can I disable the standard arguments 'help' and 'version'? In general I suggest you email the author of the cmdargs package directly, as well as cc'ing the mailing list (otherwise the author might miss this message, as I did!) In CmdArgs there is currently no way to suppress eith

[Haskell-cafe] Re: A question regarding cmdargs package

2010-10-04 Thread Ben Franksen
Arie Peterson wrote: > On Sun, 03 Oct 2010 19:18:08 +0200, Ben Franksen > wrote: >> How can I disable the standard arguments 'help' and 'version'? > > If you're not fully committed to the cmdargs package, you might try my > package 'console-program' instead >

Re: [Haskell-cafe] A question regarding cmdargs package

2010-10-04 Thread Arie Peterson
On Sun, 03 Oct 2010 19:18:08 +0200, Ben Franksen wrote: > How can I disable the standard arguments 'help' and 'version'? If you're not fully committed to the cmdargs package, you might try my package 'console-program' instead . It does not have

[Haskell-cafe] A question regarding cmdargs package

2010-10-03 Thread Ben Franksen
How can I disable the standard arguments 'help' and 'version'? Cheers ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

[Haskell-cafe] A question about "threading" state

2010-09-16 Thread michael rice
I've been playing around with State Monads. Two I looked at earlier used *sequence* and *replicate* but when I came to this one I found myself puzzling over how to structure the problem when there was no predetermined count of how many times to thread the state. == Program 1 ===

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-20 Thread C K Kashyap
Thanks Aditya...I think that is what I am looking for. On Mon, Jul 19, 2010 at 10:40 PM, aditya siram wrote: > Sorry, the previous code does not compile. It should be: > replace :: Int -> [IORef (Int,Int,Int)] -> (Int,Int,Int) -> IO () > replace index pixels new_val = do > old_val <- return $ pi

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread aditya siram
Sorry, the previous code does not compile. It should be: replace :: Int -> [IORef (Int,Int,Int)] -> (Int,Int,Int) -> IO () replace index pixels new_val = do old_val <- return $ pixels !! index writeIORef old_val new_val print_pixels = mapM_ (\p -> readIORef p >>= print) test_data :: [(Int,Int

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread aditya siram
Do you want a solution like this? import Data.IORef replace :: Int -> [IORef (Int,Int,Int)] -> (Int,Int,Int) -> IO () replace index pixels new_val = do old_val <- return $ pixels !! index writeIORef old_val new_val print_pixels = mapM (\p -> readIORef p >>= print) test_data :: [(Int,Int,Int

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread Max Rabkin
On Mon, Jul 19, 2010 at 10:17 AM, Ketil Malde wrote: > At it's heart, monads are "just" syntactic convenience, but like many > other syntactic conveniences, allows you to structure your code better. > Thus it's more about programmer efficiency than program efficiency. > (The "do notation" is synta

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread C K Kashyap
Also, Claude ... If I am correct, in your example, there is no in-place replacement happening. On Mon, Jul 19, 2010 at 2:36 PM, C K Kashyap wrote: > Okay...I think I am beginning to understand. > Is it right to assume that "magic" is backed by FFI and cannot be done in > "pure" Haskell? > > > On

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread C K Kashyap
Okay...I think I am beginning to understand. Is it right to assume that "magic" is backed by FFI and cannot be done in "pure" Haskell? On Mon, Jul 19, 2010 at 1:47 PM, Ketil Malde wrote: > C K Kashyap writes: > > > I looked at State Monad yesterday and this question popped into my mind. > > Fro

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-19 Thread Ketil Malde
C K Kashyap writes: > I looked at State Monad yesterday and this question popped into my mind. > From what I gather State Monad essentially allows the use of Haskell's do > notation to "invisibly" pass around a state. So, does the use of Monadic > style fetch us more than syntactic convenience?

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-16 Thread C K Kashyap
Hi Claude, Thanks a lot for the example. Btw, is this where you are trying in-place replacement? modifyAtIndex :: (a -> a) -> Nat -> List a -> List a modifyAtIndex f i as = let ias = zip nats as g (Tuple2 j a) = case i `eq` j of False -> a

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-16 Thread Claude Heiland-Allen
Hi, On 16/07/10 07:35, C K Kashyap wrote: Haskell without using any standard library stuff? For example, if I wanted an image representation such as this [[(Int,Int.Int)]] - basically a list of lists of 3 tuples (rgb) and wanted to do in place replacement to set the pixel values, how could I

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread C K Kashyap
Thanks Wren, Thanks Dave ... a quick question though could you point me to an example where I could build up my own in place modifiable data structure in Haskell without using any standard library stuff? For example, if I wanted an image representation such as this [[(Int,Int.Int)]] - basically a

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread wren ng thornton
C K Kashyap wrote: Thanks Daniel, Better refactorability. If you're using monadic style, changing from, say, State Thing to StateT Thing OtherMonad or from StateT Thing FirstMonad to StateT Thing SecondMonad typically requires only few changes. Explicit state-passing usually requires more cha

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread David Leimbach
On Thu, Jul 15, 2010 at 10:34 AM, C K Kashyap wrote: > Thanks David for the detailed explanation. > > A couple of quick clarifications - > > 1. Even the "invisible" state that gets modified during the monadic > evaluation is referred to as side effect right? > If the state is free of types that

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread C K Kashyap
Thanks David for the detailed explanation. A couple of quick clarifications - 1. Even the "invisible" state that gets modified during the monadic evaluation is referred to as side effect right? 2. I am a little unclear about "in-place" - does pure Haskell let one do such a thing- or does it nee

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread C K Kashyap
Thanks Daniel, Better refactorability. > If you're using monadic style, changing from, say, > State Thing > to > StateT Thing OtherMonad > > or from > StateT Thing FirstMonad > to > StateT Thing SecondMonad > > typically requires only few changes. Explicit state-passing usually > requires more cha

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread David Leimbach
On Thu, Jul 15, 2010 at 9:02 AM, C K Kashyap wrote: > Hi, > I looked at State Monad yesterday and this question popped into my mind. > From what I gather State Monad essentially allows the use of Haskell's do > notation to "invisibly" pass around a state. So, does the use of Monadic > style fetch

Re: [Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread Daniel Fischer
On Thursday 15 July 2010 18:02:47, C K Kashyap wrote: > Hi, > I looked at State Monad yesterday and this question popped into my mind. > > >From what I gather State Monad essentially allows the use of Haskell's > > do > > notation to "invisibly" pass around a state. So, does the use of Monadic > st

[Haskell-cafe] A question about State Monad and Monad in general

2010-07-15 Thread C K Kashyap
Hi, I looked at State Monad yesterday and this question popped into my mind. >From what I gather State Monad essentially allows the use of Haskell's do notation to "invisibly" pass around a state. So, does the use of Monadic style fetch us more than syntactic convenience? Again, if I understand cor

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-06-07 Thread Ryan Ingram
>> In the new type, the parameter 'a' is misleading. It has no connection to >> the >> 'a's on the right of the equals sign. You might as well write: >> >> type CB = forall a. a -> a -> a On Tue, Jun 1, 2010 at 12:40 PM, Cory Knapp wrote: > Ah! That makes sense. Which raises a new question: Is t

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-06-01 Thread Daniel Fischer
On Tuesday 01 June 2010 23:21:35, Dan Doel wrote: > I think SPJ is on record as saying it would add a lot of > complexity to the current GHC type system, > and I'm inclined to believe him. In matters concerning the GHC type system, that's a fairly natural stance, I think. __

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-06-01 Thread Dan Doel
On Tuesday 01 June 2010 3:40:41 pm Cory Knapp wrote: > > Note: this is universal quantification, not existential. > > > As I would assume. But I always see the "forall" keyword used when > discussing "existential quantification". I don't know if I've ever seen an > "exists" keyword. Is there one?

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-06-01 Thread C. McCann
On Tue, Jun 1, 2010 at 3:40 PM, Cory Knapp wrote: >> In the new type, the parameter 'a' is misleading. It has no connection to >> the >> 'a's on the right of the equals sign. You might as well write: >> >>  type CB = forall a. a -> a -> a >> > Ah! That makes sense. Which raises a new question: Is

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-06-01 Thread Jason Dagit
On Tue, Jun 1, 2010 at 12:40 PM, Cory Knapp wrote: > Thanks! That was exactly the sort of response I was looking for. > > This explains why you need to double up for your current definitions. To >> choose between two booleans (which will in turn allow you to choose >> between >> 'a's), you need a

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-06-01 Thread Cory Knapp
Thanks! That was exactly the sort of response I was looking for. This explains why you need to double up for your current definitions. To > choose between two booleans (which will in turn allow you to choose between > 'a's), you need a CB (CB a). You can eliminate the asymmetric type, though, > li

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-05-30 Thread Jason Dagit
On Sun, May 30, 2010 at 4:08 AM, wren ng thornton wrote: > Jason Dagit wrote: > >> In Church's λ-calc the types are ignored, >> > > > Not so. Church-style lambda calculus is the one where types matter; > Curry-style is the one that ignores types and evaluates as if it were the > untyped lambda ca

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-05-30 Thread Dan Doel
On Sunday 30 May 2010 12:28:36 am Cory Knapp wrote: > >type CB a = a -> a -> a > > > >ct :: CB aC > >ct x y = x > > > >cf :: CB a > >cf x y = y > > > >cand :: CB (CB a) -> CB a -> CB a > >cand p q = p q cf > > > >cor :: CB (CB a) -> CB a -> CB a > >cor p q = p ct q The reason these types are requi

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-05-30 Thread wren ng thornton
Jason Dagit wrote: In Church's λ-calc the types are ignored, Not so. Church-style lambda calculus is the one where types matter; Curry-style is the one that ignores types and evaluates as if it were the untyped lambda calculus. Church encodings are based on the untyped LC rather than Churc

Re: [Haskell-cafe] A question on existential types and Church encoding

2010-05-29 Thread Jason Dagit
On Sat, May 29, 2010 at 9:28 PM, Cory Knapp wrote: > Hello, > > A professor of mine was recently playing around during a lecture with > Church booleans (I.e., true = \x y -> x; false = \x y -> y) in Scala and > OCaml. I missed what he did, so I reworked it in Haskell and got this: > > >type CB a

[Haskell-cafe] A question on existential types and Church encoding

2010-05-29 Thread Cory Knapp
Hello, A professor of mine was recently playing around during a lecture with Church booleans (I.e., true = \x y -> x; false = \x y -> y) in Scala and OCaml. I missed what he did, so I reworked it in Haskell and got this: >type CB a = a -> a -> a >ct :: CB aC >ct x y = x >cf :: CB a >cf x y = y

Re: [Haskell-cafe] A question on DSL's

2010-01-04 Thread Tom Hawkins
On Mon, Jan 4, 2010 at 9:41 PM, Luke Palmer wrote: > On Mon, Jan 4, 2010 at 12:16 PM, Tom Hawkins wrote: >> One argument for option 2 is to carry forward datatypes to the target >> language.  For example, if you want to describe a state machine with >> the state as a type: > > What do you mean "c

Re: [Haskell-cafe] A question on DSL's

2010-01-04 Thread Luke Palmer
On Mon, Jan 4, 2010 at 12:16 PM, Tom Hawkins wrote: > One argument for option 2 is to carry forward datatypes to the target > language.  For example, if you want to describe a state machine with > the state as a type: What do you mean "carry forward". Can you elaborate on your simple example? W

Re: [Haskell-cafe] A question on DSL's

2010-01-04 Thread Tom Hawkins
One argument for option 2 is to carry forward datatypes to the target language. For example, if you want to describe a state machine with the state as a type: data StopLightState = Red | Yellow | Green With option 1, values of type StopLightState will be resolved at compile-time, not run-time.

Re: [Haskell-cafe] A question on DSL's

2010-01-04 Thread CK Kashyap
Mon, January 4, 2010 10:51:06 PM >Subject: Re: [Haskell-cafe] A question on DSL's > > >To start with, can you clarify that you are looking for an Embedded DSL >(sometimes called Light Weight DSL)? > > >A _proper_ DSL has its own interpreter/compiler where an EDSL/LwDS

Re: [Haskell-cafe] A question on DSL's

2010-01-04 Thread John Van Enk
To start with, can you clarify that you are looking for an Embedded DSL (sometimes called Light Weight DSL)? A _proper_ DSL has its own interpreter/compiler where an EDSL/LwDSL leverages the compiler of a host language (in this case, Haskell). Assuming you're referring to an EDSL, I'll respond. :

Re: [Haskell-cafe] A question on DSL's

2010-01-04 Thread Jasper Van der Jeugt
Hello, I see no real reason to use the second approach, unless you're doing something tremendously new and big. Besides, the first solution is much easier and will be easier to maintain (in case the back end changes). Kind regards, Jasper Van der Jeugt On Mon, Jan 4, 2010 at 6:14 PM, CK Kashyap

[Haskell-cafe] A question on DSL's

2010-01-04 Thread CK Kashyap
Hi, I am not sure if I'm using DSL in the right context here but I am referring to those solutions that allow us to write code in Haskell and generate a target code source code of another language or even object code for that matter. I am aware of two ways of achieving this - 1. Implement funct

  1   2   3   >