Re: [Haskell-cafe] Help me understand general recursion from cata- and anamorphism

2013-06-23 Thread Takayuki Muranushi
Dear all, https://github.com/nushio3/practice/blob/master/recursion-schemes/FibTest.hs After learning fix-point operators, I found an answer by myself. ``` fibBase :: (Integer - Integer) - Integer - Integer fibBase fib n | n = 1= 1 | otherwise = fib (n-1) + fib (n-2) fibWithFix ::

[Haskell-cafe] Help me understand general recursion from cata- and anamorphism

2013-06-16 Thread Takayuki Muranushi
In an attempt to understand why cata- and anamorphisms are considered so important, I found multiple implications that you can write any recursive functions in terms of nonrecursive functions and ana, cata (am I right here?) so I'm trying to practice the rewrite by a few functions. I'm following a

[Haskell-cafe] help understanding zlib space leak

2013-05-05 Thread diego souza
Dear haskellers, I'd like assistance figuring out a strange space leak using zlib package. To make it easier to reproduce I've come up with the following snippet that pretty much resumes up the problem I'm trying to solve: -- omitting imports and function signatures encode = compress .

Re: [Haskell-cafe] help understanding zlib space leak

2013-05-05 Thread diego souza
Sorry, I should've removed the pid number from the output. The following should be correct: $ sudo dd if=/dev/sda bs=4K count=2048K | ./test +RTS -M1M -s /dev/null ... 8589934592 bytes (8.6 GB) copied, 243.525 s, 35.3 MB/s 41,942,119,192

Re: [Haskell-cafe] Help to write type-level function

2013-02-27 Thread Raphael Gaschignard
I think it might be impossible with type families. I don't think it's possible to differentiate with type families something like T a a, and T a b, with b different from a. I think that you would need overlap to write this.

Re: [Haskell-cafe] Help to write type-level function

2013-02-27 Thread Aleksey Khudyakov
On 27 February 2013 12:01, Raphael Gaschignard dasur...@gmail.com wrote: I think it might be impossible with type families. I don't think it's possible to differentiate with type families something like T a a, and T a b, with b different from a. It's indeed impossible to write such type

[Haskell-cafe] Help to write type-level function

2013-02-27 Thread oleg
Dmitry Kulagin wrote: I try to implement typed C-like structures in my little dsl. HList essentially had those http://code.haskell.org/HList/ I was unable to implement required type function: type family Find (s :: Symbol) (xs :: [(Symbol,Ty)]) :: Ty Which just finds a type in a

Re: [Haskell-cafe] Help to write type-level function

2013-02-27 Thread Dmitry Kulagin
That seems to be very relevant to my problem (especially HList.Record). Am I right that UndecidableInstances is required mostly because of eq on types, like in this instances: class HRLabelSet (ps :: [*]) instance HRLabelSet '[] instance HRLabelSet '[x] instance ( HEq l1 l2 leq ,

Re: [Haskell-cafe] Help to write type-level function

2013-02-27 Thread Dmitry Kulagin
Very clear solution, I will try to adopt it. Thank you! On Wed, Feb 27, 2013 at 12:17 PM, Aleksey Khudyakov alexey.sklad...@gmail.com wrote: On 27 February 2013 12:01, Raphael Gaschignard dasur...@gmail.com wrote: I think it might be impossible with type families. I don't think it's

Re: [Haskell-cafe] Help to write type-level function

2013-02-27 Thread Dmitry Kulagin
Hi Aleksey, Unfortunately, your solution does not work for me (ghc 7.6.2). I reduced the problem to: -- | Type class for type equality. class TypeEq (a :: α) (b :: α) (eq :: Bool) | a b - eq instance TypeEq a a True -- instance TypeEq a b False instance eq ~ False = TypeEq a b eq

Re: [Haskell-cafe] Help to write type-level function

2013-02-27 Thread Aleksey Khudyakov
On 27.02.2013 17:35, Dmitry Kulagin wrote: Hi Aleksey, Unfortunately, your solution does not work for me (ghc 7.6.2). I reduced the problem to: -- | Type class for type equality. class TypeEq (a :: α) (b :: α) (eq :: Bool) | a b - eq instance TypeEq a a True -- instance TypeEq a

Re: [Haskell-cafe] Help to write type-level function

2013-02-27 Thread Dmitry Kulagin
Oh, that is my fault - I was sure that I specified the extension and it didn't help. It really works with OverlappingUndecidable. Thank you! On Wed, Feb 27, 2013 at 10:36 PM, Aleksey Khudyakov alexey.sklad...@gmail.com wrote: On 27.02.2013 17:35, Dmitry Kulagin wrote: Hi Aleksey,

[Haskell-cafe] Help to write type-level function

2013-02-26 Thread Dmitry Kulagin
Hi, I try to implement typed C-like structures in my little dsl. I was able to express structures using type-level naturals (type Ty is promoted): data Ty = TInt | TBool | TStruct Symbol [Ty] That allowed to implement all needed functions, including type-level function: type family Get (n ::

Re: [Haskell-cafe] help diagnosing space leak with IORef/STRef, just incrementing a million times.

2013-01-06 Thread Albert Y. C. Lai
On 13-01-07 12:12 AM, Thomas Hartman wrote: I have a space leak in a function that increments a number inside IORef or STRef (either lazy or strict). IORef and STRef operations do not automatically evaluate contents. writeIORef r (x + 1) simply stores a pointer to the expression (thunk) x +

[Haskell-cafe] help diagnosing space leak with IORef/STRef, just incrementing a million times.

2013-01-06 Thread Thomas Bereknyei
I have had issues like this with modifySTRef before. Try to make a strict version modifySTRef' If memory serves, something like this worked for me. modifySTRef' r f = do a - readSTRef r writeSTRef r $! f a ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] help diagnosing space leak with IORef/STRef, just incrementing a million times.

2013-01-06 Thread Christopher Done
A similar use-case and same solution with IORefs: http://hpaste.org/diff/80055/80058 Guess which one threw a stackoverflow and which one ran indefinitely when given a few hundred million lines of input. On 7 January 2013 07:35, Albert Y. C. Lai tre...@vex.net wrote: On 13-01-07 12:12 AM, Thomas

Re: [Haskell-cafe] Help optimize fannkuch program

2012-12-08 Thread Branimir Maksimovic
Here it is :http://shootout.alioth.debian.org/u64/program.php?test=fannkuchreduxlang=ghcid=4 Date: Mon, 3 Dec 2012 15:32:20 -0800 Subject: Re: [Haskell-cafe] Help optimize fannkuch program From: b...@serpentine.com To: bm...@hotmail.com CC: haskell-cafe@haskell.org On Mon, Dec 3, 2012 at 11:18

Re: [Haskell-cafe] Help optimize fannkuch program

2012-12-03 Thread Bryan O'Sullivan
On Sun, Dec 2, 2012 at 3:12 PM, Branimir Maksimovic bm...@hotmail.comwrote: Well, playing with Haskell I have literally trasnlated my c++ program http://shootout.alioth.debian.org/u64q/program.php?test=fannkuchreduxlang=gppid=3 and got decent performance but not that good in comparison with

Re: [Haskell-cafe] Help optimize fannkuch program

2012-12-03 Thread Branimir Maksimovic
mine version.Thanks ! Should I contribute your version on shootout site? Date: Mon, 3 Dec 2012 00:01:32 -0800 Subject: Re: [Haskell-cafe] Help optimize fannkuch program From: b...@serpentine.com To: bm...@hotmail.com CC: haskell-cafe@haskell.org On Sun, Dec 2, 2012 at 3:12 PM, Branimir Maksimovic bm

Re: [Haskell-cafe] Help optimize fannkuch program

2012-12-03 Thread Bryan O'Sullivan
On Mon, Dec 3, 2012 at 11:18 AM, Branimir Maksimovic bm...@hotmail.comwrote: Thanks ! Should I contribute your version on shootout site? Do whatever you like with it. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

[Haskell-cafe] Help optimize fannkuch program

2012-12-02 Thread Branimir Maksimovic
Well, playing with Haskell I have literally trasnlated my c++ program http://shootout.alioth.debian.org/u64q/program.php?test=fannkuchreduxlang=gppid=3and got decent performance but not that good in comparisonwith c++ On my machine Haskell runs 52 secs while c++ 30 secs.(There is Haskell entry

Re: [Haskell-cafe] Help: Main: thread blocked in MVar operation

2012-11-04 Thread José A. Lopes
Hey, So, I couldn't really get a small code sample. But I have a new example of the same problem. Anyway, let me just give you the overall picture. I am building an interpreter and I want to evaluate the definition of a recursive function. This entails registering the function symbol in the

[Haskell-cafe] Help: Main: thread blocked in MVar operation

2012-10-23 Thread José A. Lopes
Hey everyone, I changed my code I now I get the following error message Main: thread blocked indefinitely in an MVar operation Before the change, I was using the State monad with runState. Then, I changed the code to use the StateT monad transformer wrapped around IO monad and runStateT.

Re: [Haskell-cafe] Help: Main: thread blocked in MVar operation

2012-10-23 Thread Joey Adams
On Tue, Oct 23, 2012 at 5:03 PM, José A. Lopes jose.lo...@ist.utl.pt wrote: Hey everyone, I changed my code I now I get the following error message Main: thread blocked indefinitely in an MVar operation Before the change, I was using the State monad with runState. Then, I changed the

[Haskell-cafe] Help me with space leaks

2012-09-26 Thread Alexey Uimanov
Hello. I am trying to write some thing in haskell and i need fast storage to store and select this things from storage. https://github.com/s9gf4ult/projs/tree/master/haskell/teststorage I am writing simple testing package to determine my needs and select the fastest storage and i have encountered

[Haskell-cafe] Help a young graduate haskeller to land its dream job

2012-09-12 Thread Alfredo Di Napoli
Hi everyone, If this mail sound strange to you, you are free to ignore it. My name is Alfredo Di Napoli and I'm a 24-year-old programmer from Rome, Italy. I've graduated in May and I'm currently working as an intern for a company involved in the defence field. In my spare time, though, I study

Re: [Haskell-cafe] Help a young graduate haskeller to land its dream job

2012-09-12 Thread Eugene Kirpichov
Hi Alfredo, You might look at the various bigdata companies. I was surprised by how many of them are using Scala or Clojure - it's definitely over 50%. Looks like FP is really gaining traction in this area. On Wed, Sep 12, 2012 at 11:48 AM, Alfredo Di Napoli alfredo.dinap...@gmail.com wrote: Hi

[Haskell-cafe] Help requested: naming things in conduit

2012-06-28 Thread Michael Snoyman
Hi all, I'm just about ready to make the 0.5 release of conduit. And as usual, I'm running up against the hardest thing in programming: naming things. Here's the crux of the matter: in older versions of conduit, functions would have a type signature of Source, Sink, or Conduit. For example:

Re: [Haskell-cafe] Help requested: naming things in conduit

2012-06-28 Thread Paolo Capriotti
On Thu, Jun 28, 2012 at 6:11 PM, Michael Snoyman mich...@snoyman.com wrote: Hi all, I'm just about ready to make the 0.5 release of conduit. And as usual, I'm running up against the hardest thing in programming: naming things. Here's the crux of the matter: in older versions of conduit,

Re: [Haskell-cafe] Help requested: naming things in conduit

2012-06-28 Thread Michael Snoyman
On Thu, Jun 28, 2012 at 8:36 PM, Paolo Capriotti p.caprio...@gmail.com wrote: On Thu, Jun 28, 2012 at 6:11 PM, Michael Snoyman mich...@snoyman.com wrote: Hi all, I'm just about ready to make the 0.5 release of conduit. And as usual, I'm running up against the hardest thing in programming:

Re: [Haskell-cafe] help with safecopy + acid-state

2012-01-31 Thread Johannes Waldmann
Can I really rename  old.T = new.T_orig ? It looks as if then tries to load the wrong acid-state snapshot. The name of your data type doesn't matter as acid-state doesn't store that on the disk. I think it does - because file names are state/T/*.log and so on? J.W.

Re: [Haskell-cafe] help with safecopy + acid-state

2012-01-31 Thread Antoine Latter
On Tue, Jan 31, 2012 at 8:27 AM, Johannes Waldmann waldm...@imn.htwk-leipzig.de wrote: Can I really rename  old.T = new.T_orig ? It looks as if then tries to load the wrong acid-state snapshot. The name of your data type doesn't matter as acid-state doesn't store that on the disk. I

Re: [Haskell-cafe] help with safecopy + acid-state

2012-01-30 Thread Johannes Waldmann
Felipe Almeida Lessa felipe.lessa at gmail.com writes: data T_orig = T_orig Foo $(deriveSafeCopy 0 'base ''T_orig) data T = T Foo Bar $(deriveSafeCopy 0 'extension ''T) instance Migrate T where type MigrateFrom T = T_Orig ... As you can read from deriveSafeCopy's documentation [1],

Re: [Haskell-cafe] help with safecopy + acid-state

2012-01-30 Thread Felipe Almeida Lessa
On Mon, Jan 30, 2012 at 4:46 PM, Johannes Waldmann waldm...@imn.htwk-leipzig.de wrote: Thanks - which zero? (there are two of them.) You should not change the deriveSafeCopy of your old data type. The only allowed change is renaming your data type (see below). You should increment the version

[Haskell-cafe] help with safecopy + acid-state

2012-01-27 Thread Johannes Waldmann
Dear all, I can't quite get safecopy to work with acid-state: old version of code : data T = T Foo $(deriveSafeCopy 0 'base ''T) new version : data T_orig = T_orig Foo $(deriveSafeCopy 0 'base ''T_orig) data T = T Foo Bar $(deriveSafeCopy 0 'extension ''T) instance Migrate T where type

Re: [Haskell-cafe] help with safecopy + acid-state

2012-01-27 Thread Felipe Almeida Lessa
On Fri, Jan 27, 2012 at 3:04 PM, Johannes Waldmann waldm...@imn.htwk-leipzig.de wrote: data T_orig = T_orig Foo $(deriveSafeCopy 0 'base ''T_orig) data T = T Foo Bar $(deriveSafeCopy 0 'extension ''T) instance Migrate T where type MigrateFrom T = T_Orig ... As you can read from

Re: [Haskell-cafe] Help understanding Haskell runtime costs

2011-08-11 Thread Henning Thielemann
On 09.08.2011 01:43, Thiago Negri wrote: Hello all, I'm relatively new to Haskell and trying to solve some online judge's problems in it. One of the problems is to say if a given sentence is a tautogram or not. A tautogram is just a sentence with all the words starting with the same letter. My

Re: [Haskell-cafe] Help understanding Haskell runtime costs

2011-08-11 Thread Thiago Negri
So, thanks to Henning Thielemann I was able to make a code a little more functional. I did find ByteString module that really speed things up. I got 0.04 seconds with the following snippet: -- code start import qualified Data.ByteString.Char8 as BS import Data.Char (toLower) main :: IO () main

[Haskell-cafe] Help understanding Haskell runtime costs

2011-08-08 Thread Thiago Negri
Hello all, I'm relatively new to Haskell and trying to solve some online judge's problems in it. One of the problems is to say if a given sentence is a tautogram or not. A tautogram is just a sentence with all the words starting with the same letter. My first try (solution is ok) was to do it as

Re: [Haskell-cafe] Help

2011-06-27 Thread Stoyan Peev
Yes, how can i miss that... It's working now, but still it works only for the first element of the list. It prints the result only for the first string. Now when it's operational, i have just to modify it to be working for all of the elements of the list. If i run the program right now, the

Re: [Haskell-cafe] Help

2011-06-27 Thread Daniel Patterson
so think about the high level design for a second, and let that guide the types. then the types should guide the code. p, which I assume is the top level evaluation, is supposed to take a list of strings, and produce a list of integers (the result of evaluating the expression), right? So it

Re: [Haskell-cafe] Help

2011-06-27 Thread Stoyan Peev
Yeah, that really helped me :)) Finally i got the results i wanted : Main p [2*34/3,2+3,2*(6/2)] [22,5,6] There is only one more question i have about this. I have already written 2 error captures, but they don't really apply to the task i have. Here are my error captures:

Re: [Haskell-cafe] Help

2011-06-27 Thread Daniel Patterson
Well, if you are at all familiar with (or wanted to learn about) the Maybe type, I would suggest you use that. A brief synopsis: data Maybe a = Nothing | Just a Which means that a Maybe Int is either Nothing or or Just an int. If you were to got this path, then your p function should have

Re: [Haskell-cafe] Help

2011-06-25 Thread Stoyan Peev
First I am using WinHugs. that's the code i made so far but it's still not working: http://hpaste.org/48318 Error: ERROR file:.\kursovazadacha.hs:36 - Type error in explicitly typed binding *** Term : p *** Type : [String] - [a] *** Does not match : [String] - Int I'm

Re: [Haskell-cafe] Help

2011-06-25 Thread Jack Henahan
The error in ghci is Couldn't match expected type `Int' with actual type `[a0]' In the expression: [] In an equation for `p': p [] = [] You've defined p as [String] - Int, but then your base case is p [] = []. [] is not an Int. I changed it to 0 and it'll compile, at least, but I'm not

[Haskell-cafe] Help

2011-06-24 Thread Stoyan Peev
Hello all, I am experiencing some issues to do my course task in university. I have to write a calculator- function in Haskell. The function argument is a list of strings and also form such list, as each string of the argument made definite action: - If the string has the form of an arithmetic

Re: [Haskell-cafe] Help

2011-06-24 Thread Daniel Patterson
What have you tried to do in order to make it work for the list, and what error results? What is confusing about the error message? More generally, how could you transform an operation on a single string into one that does the same thing to a list of strings? You've probably talked about higher

Re: [Haskell-cafe] Help

2011-06-24 Thread Stoyan Peev
I found the library myself, and i already put the code in that site: http://hpaste.org/48277 That's what i have tried to do for making the task by calling the one string function by another one: include kursovazadacha parse :: [a] - [a] parse [] = [] parse (x:xs) = eval (x:xs) The error

Re: [Haskell-cafe] Help

2011-06-24 Thread Daniel Patterson
what haskell compiler are you using? And what does the include line do? That does not look like a GHC error message (the only compiler I'm familiar with), but it seems like it is saying that you should not have the extra newlines between the function type signature and declaration. - that's

Re: [Haskell-cafe] help with dynamic load

2011-03-26 Thread Rob Nikander
On Fri, Mar 25, 2011 at 9:52 PM, Bernie Pope florbit...@gmail.com wrote: On 26 March 2011 05:57, Rob Nikander rob.nikan...@gmail.com wrote: \begin{comment} -- A work-around for Dynamics. The keys used to compare two TypeReps are -- somehow not equal for the same type in hs-plugin's loaded

[Haskell-cafe] help with dynamic load

2011-03-25 Thread Rob Nikander
Hi all, I'm trying to use the 'plugins' package. Since I already posted to stackoverflow I'll just link to that. I posted a simple program that I thought would work, but mostly doesn't. Any pointers, appreciated.

Re: [Haskell-cafe] help with dynamic load

2011-03-25 Thread Bernie Pope
On 26 March 2011 05:57, Rob Nikander rob.nikan...@gmail.com wrote: I'm trying to use the 'plugins' package.  Since I already posted to stackoverflow I'll just link to that.  I posted a simple program that I thought would work, but mostly doesn't.   Any pointers, appreciated.

Re: [Haskell-cafe] Help optimising a Haskell program

2011-03-23 Thread David MacIver
On 22 March 2011 15:49, Jason Dagit dag...@gmail.com wrote: This seems to consistently give about a 0.4s improvement, which isn't nothing but isn't a particularly interesting chunck of 8s (actually it's 8.4s - 8s). Setting it to 256M doesn't make any difference. You should use criterion to

Re: [Haskell-cafe] Help optimising a Haskell program

2011-03-22 Thread David MacIver
On 22 March 2011 02:00, Jesper Louis Andersen jesper.louis.ander...@gmail.com wrote: On Tue, Mar 22, 2011 at 00:59, David MacIver da...@drmaciver.com wrote: It's for rank aggregation - taking a bunch of partial rankings of some items from users and turning them into an overall ranking (aka

Re: [Haskell-cafe] Help optimising a Haskell program

2011-03-22 Thread Jesper Louis Andersen
On Tue, Mar 22, 2011 at 09:11, David MacIver da...@drmaciver.com wrote:  Productivity  85.0% of total user, 85.0% of total elapsed That is somewhat ok. So much for hoping GC tuning would yield an improvement. -- J. ___ Haskell-Cafe mailing list

Re: [Haskell-cafe] Help optimising a Haskell program

2011-03-22 Thread Jason Dagit
On Tue, Mar 22, 2011 at 1:11 AM, David MacIver da...@drmaciver.com wrote: On 22 March 2011 02:00, Jesper Louis Andersen jesper.louis.ander...@gmail.com wrote: On Tue, Mar 22, 2011 at 00:59, David MacIver da...@drmaciver.com wrote: It's for rank aggregation - taking a bunch of partial

[Haskell-cafe] Help optimising a Haskell program

2011-03-21 Thread David MacIver
Hi, I have a Haskell program I'm trying to optimise, and could use some assistance. It's for rank aggregation - taking a bunch of partial rankings of some items from users and turning them into an overall ranking (aka That thing that Hammer Principle does). The code is here:

Re: [Haskell-cafe] Help optimising a Haskell program

2011-03-21 Thread Jesper Louis Andersen
On Tue, Mar 22, 2011 at 00:59, David MacIver da...@drmaciver.com wrote: It's for rank aggregation - taking a bunch of partial rankings of some items from users and turning them into an overall ranking (aka That thing that Hammer Principle does). Two questions immediately begs themselves: *

Re: [Haskell-cafe] Help optimising a Haskell program

2011-03-21 Thread Johan Tibell
You use a lot of (linked lists). Are they all used to represent streams or are they actually manifest during runtime? If it's the latter switch to a better data structure, like Vector. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Help with how to concatenate with own datatypes

2011-03-11 Thread eldavido
Yeah, that works! Thanks! -- View this message in context: http://haskell.1045720.n5.nabble.com/Help-with-how-to-concatenate-with-own-datatypes-tp3424433p3425325.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___

[Haskell-cafe] Help with how to concatenate with own datatypes

2011-03-10 Thread eldavido
Hi, I´m doing a project in haskell and I need to define an operator that concatenate some own defined data types, just like the operator ++ does for lists. I don´t see how to define the operator recursively since this adding function (:) doesn´t work on my own data types. This is my code: data

Re: [Haskell-cafe] Help with how to concatenate with own datatypes

2011-03-10 Thread Antoine Latter
On Thu, Mar 10, 2011 at 7:41 PM, eldavido eldavi...@hotmail.com wrote: Hi, I´m doing a project in haskell and I need to define an operator that concatenate some own defined data types, just like the operator ++ does for lists. I don´t see how to define the operator recursively since this

Re: [Haskell-cafe] help for the usage on mfix

2011-02-23 Thread Ryan Ingram
Just write a loop: let loop gs gu | Just z - find_obj gu usyms = do ... (gs', gu') - handle_obj_ar ... loop gs' gu' | otherwise = return (gs,gu) (gs, gu) - loop def undef mfix is for when you have mutually recursive data but you want the IO operation

[Haskell-cafe] help for the usage on mfix

2011-02-22 Thread Gang Yu
hello cafe, I just want to do cursion to a fixpoint in an IO function, I write sth. like this, handle_ar::(Set String,Set String)-FilePath- IO (Set String, Set String) handle_ar (def,undef) ar=do let gs = def gu = undef syms - liftM (map (\x - (symb x, x))) $ defined_syms ar usyms

Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-17 Thread Henning Thielemann
On Tue, 8 Feb 2011, C K Kashyap wrote: I need to convert IOArray to bytestring as shown below -  import Data.Array.IO import Data.Binary.Put import qualified Data.ByteString.Lazy as BS import Data.Word main = do arr - newArray (0,9) 0 :: IO (IOArray Int Int) let bs=toByteString arr return ()

[Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread C K Kashyap
Hi, I need to convert IOArray to bytestring as shown below - import Data.Array.IO import Data.Binary.Put import qualified Data.ByteString.Lazy as BS import Data.Word main = do arr - newArray (0,9) 0 :: IO (IOArray Int Int) let bs=toByteString arr return () How can I implement the 'toByteString'

Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread Michael Snoyman
Your array contains machine-sized Ints, which in practice are likely either 32-bit or 64-bit, while a ByteString is the equivalent of an array or 8-bit values. So you'll need to somehow convert the Ints to Word8s. Do you know if you need big or little endian? A basic approach would be: * Use

Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread C K Kashyap
On Tue, Feb 8, 2011 at 2:26 PM, Michael Snoyman mich...@snoyman.com wrote: Your array contains machine-sized Ints, which in practice are likely either 32-bit or 64-bit, while a ByteString is the equivalent of an array or 8-bit values. So you'll need to somehow convert the Ints to Word8s. Do

Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread Michael Snoyman
On Tue, Feb 8, 2011 at 11:13 AM, C K Kashyap ckkash...@gmail.com wrote: On Tue, Feb 8, 2011 at 2:26 PM, Michael Snoyman mich...@snoyman.com wrote: Your array contains machine-sized Ints, which in practice are likely either 32-bit or 64-bit, while a ByteString is the equivalent of an array

Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread C K Kashyap
1) Just use Data.Word.Word8 instead of the second Int in your type sig for IOArray 2) Use getElems to get a [Word8] 3) Data.ByteString.pack converts a [Word8] into a ByteString Michael I am currently using a list of tuples - [(Int,Int,Int)] to represent an image buffer. You can see it in

Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread Ketil Malde
C K Kashyap ckkash...@gmail.com writes: I am currently using a list of tuples - [(Int,Int,Int)] to represent an image buffer. [...] Looks like this is pretty slow, Unsurprisingly, as there's a huge space overhead, and (depending on usage, but probably even worse) linear access time. I

Re: [Haskell-cafe] Help needed for converting IOArray to ByteString

2011-02-08 Thread Gábor Lehel
On Tue, Feb 8, 2011 at 10:39 AM, C K Kashyap ckkash...@gmail.com wrote: 1) Just use Data.Word.Word8 instead of the second Int in your type sig for IOArray 2) Use getElems to get a [Word8] 3) Data.ByteString.pack converts a [Word8] into a ByteString Michael I am currently using a list of

[Haskell-cafe] Help!! Cannot get RandT and liftIO to work together...

2010-12-23 Thread JP Moresmau
Hello all, sorry I must have taken my stupid pills this morning, I cannot get the following code to compile, what am I missing? data MyState=MyState Integer newState:: (RandomGen g) = RandT g IO MyState newState = do time-liftIO getCPUTime rand-getRandomR (1,6) return $

Re: [Haskell-cafe] Help!! Cannot get RandT and liftIO to work together...

2010-12-23 Thread Daniel Fischer
On Thursday 23 December 2010 15:52:40, JP Moresmau wrote: Hello all, sorry I must have taken my stupid pills this morning, I cannot get the following code to compile, what am I missing? Works here. Which versions of the packages and GHC are you using?

Re: [Haskell-cafe] Help!! Cannot get RandT and liftIO to work together...

2010-12-23 Thread Daniel Fischer
On Thursday 23 December 2010 15:52:40, JP Moresmau wrote: what am I missing? Maybe I just spotted it: But the MonadRandom docs say: Instances: MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control- Monad-IO-Class.html#t:MonadIO m links to the

Re: [Haskell-cafe] Help!! Cannot get RandT and liftIO to work together...

2010-12-23 Thread JP Moresmau
GHC 6.12.1, base 4.2.0.0, MonadRandom-0.1.6, transformers-0..2.2.0, on Windows.Could it be that my system is not picking up the MonadIO I think it does? JP On Thu, Dec 23, 2010 at 4:13 PM, Daniel Fischer daniel.is.fisc...@googlemail.com wrote: On Thursday 23 December 2010 15:52:40, JP

Re: [Haskell-cafe] Help!! Cannot get RandT and liftIO to work together...

2010-12-23 Thread Daniel Fischer
On Thursday 23 December 2010 16:21:05, JP Moresmau wrote: GHC 6.12.1, base 4.2.0.0, MonadRandom-0.1.6, transformers-0..2.2.0, on Windows. Could it be that my system is not picking up the MonadIO I think it does? Probably. With 6.12.1, you'll probably have an mtl-1.* installed, so the

Re: [Haskell-cafe] Help!! Cannot get RandT and liftIO to work together...

2010-12-23 Thread JP Moresmau
Thanks a million, it worked! Following all the dependencies sometimes is a bit of a headache. But in a sense, I'm happy to see I had understood how to use the monad transformer correctly, it wasn't me being (too) stupid. Thanks again! JP On Thu, Dec 23, 2010 at 4:32 PM, Daniel Fischer

[Haskell-cafe] Help with lhs2TeX

2010-12-11 Thread Dominic Steintiz
Hi, I wonder if someone could point out what I am doing wrong. My understanding was that I should be able to create a .lhs file and run it e.g. with ghci and then use lhs2TeX to create a nice .pdf file, all from the same source. I can produce nice slides but unfortunately the .lhs does compile

Re: [Haskell-cafe] Help with lhs2TeX

2010-12-11 Thread Ralf Hinze
Hi Dominic, Hi, I wonder if someone could point out what I am doing wrong. My understanding was that I should be able to create a .lhs file and run it e.g. with ghci and then use lhs2TeX to create a nice .pdf file, all from the same source. I can produce nice slides but unfortunately the .lhs

Re: [Haskell-cafe] Help with lhs2TeX

2010-12-11 Thread Dominic Steintiz
the basic approach (originally) is to have an executable Haskell program so that you can typecheck it. Then you add some %format directives to make it look nice, eg. %format Mu f = \mu f %format in_ = in^\circ should do the job. Hth, Ralf It certainly does. Obvious really (as are

Re: [Haskell-cafe] Help defining a Typeable polymorphic-state monad transformer

2010-12-07 Thread Brandon Simmons
On Mon, Dec 6, 2010 at 11:53 PM, Luke Palmer lrpal...@gmail.com wrote: This has nothing to do with a monad.  This is just about data.  You want a type that can contain any Typeable type, and a safe way to cast out of that type into the type that came in.  Such a thing exists, it's called

[Haskell-cafe] Help defining a Typeable polymorphic-state monad transformer

2010-12-06 Thread Brandon Simmons
Hi all, I gave myself until this evening to figure this out on my own, and time is up! Hopefully this makes for a good discussion, though the idea could be dumb. What I'm trying to do is define a state monad in which the passed state can change type during the computation. The only constraint is

Re: [Haskell-cafe] Help defining a Typeable polymorphic-state monad transformer

2010-12-06 Thread Luke Palmer
This has nothing to do with a monad. This is just about data. You want a type that can contain any Typeable type, and a safe way to cast out of that type into the type that came in. Such a thing exists, it's called Data.Dynamic. Then your monad is just StateT Dynamic, where your magical

Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Serguey Zefirov
2010/10/27 Andy Stewart lazycat.mana...@gmail.com: Hi all, I want use TH write some function like below:  data DataType = StringT                | IntT                | CharT  parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN) Example:  parse [(string, StringT), (001, IntT), (c,

Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Andy Stewart
Serguey Zefirov sergu...@gmail.com writes: 2010/10/27 Andy Stewart lazycat.mana...@gmail.com: Hi all, I want use TH write some function like below:  data DataType = StringT                | IntT                | CharT  parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN) Example:

Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Jonas Almström Duregård
Unless you have a 'real' type for parse sometime during compile time, TH won't be able to generate it. A good rule of thumbs is that if you can't write the code yourself, then you can't get TH to do it either. /J On 27 October 2010 08:50, Andy Stewart lazycat.mana...@gmail.com wrote: Serguey

Re: [Haskell-cafe] Help me TH code.

2010-10-27 Thread Serguey Zefirov
2010/10/27 Andy Stewart lazycat.mana...@gmail.com: Serguey Zefirov sergu...@gmail.com writes: I think that you should use TH properly, without compiler and logical errors. What actually do you want? I'm build multi-processes communication program. You don't need TH here, I think. You can

[Haskell-cafe] Help me TH code.

2010-10-26 Thread Andy Stewart
Hi all, I want use TH write some function like below: data DataType = StringT | IntT | CharT parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN) Example: parse [(string, StringT), (001, IntT), (c, CharT)] will return: (string, 001, 'c') So how

[Haskell-cafe] HELP

2010-10-21 Thread Yaadallah Khan
I am Studying for an exam, and i have just come accross the following 3 questions, i am not familiar with the functions, therefore i would appreciate any help. !! i have already created painting 2 3 all i need is the 3 functions, for the three different tasks as shown below. the functions are

Re: [Haskell-cafe] HELP

2010-10-21 Thread Brian Troutwine
I'm not sure what you're asking for; it looks like you have to implement the functions from the specifications. On Thu, Oct 21, 2010 at 6:11 PM, Yaadallah Khan yk...@hotmail.com wrote: I am Studying for an exam, and i have just come accross the following 3 questions, i am not familiar with the

Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-29 Thread Henning Thielemann
S. Doaitse Swierstra schrieb: Avoiding repeated additions: movingAverage :: Int - [Float] - [Float] movingAverage n l = runSums (sum . take n $l) l (drop n l) where n' = fromIntegral n runSums sum (h:hs) (t:ts) = sum / n' : runSums (sum-h+t) hs ts runSums _

Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-29 Thread S. Doaitse Swierstra
On 29 sep 2010, at 00:58, o...@cs.otago.ac.nz wrote: Avoiding repeated additions: movingAverage :: Int - [Float] - [Float] movingAverage n l = runSums (sum . take n $l) l (drop n l) where n' = fromIntegral n runSums sum (h:hs) (t:ts) = sum / n' : runSums (sum-h+t) hs ts

Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-28 Thread S. Doaitse Swierstra
Avoiding repeated additions: movingAverage :: Int - [Float] - [Float] movingAverage n l = runSums (sum . take n $l) l (drop n l) where n' = fromIntegral n runSums sum (h:hs) (t:ts) = sum / n' : runSums (sum-h+t) hs ts runSums _ _ [] = [] Doaitse On 28

[Haskell-cafe] Help us test gtk2hs darcs!

2010-09-27 Thread Andy Stewart
Hi all, We have add many APIs in gtk2hs darcs, and ready to release gtk2hs-0.12.0 Please help us test gtk2hs darcs, we can fix it before release gtk2hs-0.12.0 You can get gtk2hs darcs with below command: darcs get code.haskell.org/gtk2hs Please send any bug report to

Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-27 Thread Richard O'Keefe
On 27/09/2010, at 5:20 AM, rgowka1 wrote: Type signature would be Int - [Double] - [(Double,Double)] Any thoughts or ideas on how to calculate a n-element moving average of a list of Doubles? Let's say [1..10]::[Double] what is the function to calculate the average of the 3 elements?

[Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-26 Thread rgowka1
Type signature would be Int - [Double] - [(Double,Double)] Any thoughts or ideas on how to calculate a n-element moving average of a list of Doubles? Let's say [1..10]::[Double] what is the function to calculate the average of the 3 elements? [(1,0),(2,0),(3,2),(4,3)] :: [(Double,Double)]

Re: [Haskell-cafe] Help to create a function to calculate a n element moving average ??

2010-09-26 Thread Serguey Zefirov
2010/9/26 rgowka1 rgow...@gmail.com: Type signature would be Int - [Double] - [(Double,Double)] Any thoughts or ideas on how to calculate a n-element moving average of a list of Doubles? Let's say [1..10]::[Double] what is the function to calculate the average of the 3 elements?

Re: [Haskell-cafe] help me evangelize haskell.

2010-09-07 Thread C K Kashyap
Hi Dan, This presentation is really nice. I went over it a couple of times and I think this ppt will help me try to use Haskell for things that I usually use Perl for :) A quick question - import Process bombs on my GHCI(The Glorious Glasgow Haskell Compilation System, version 6.12.3) -what do I

Re: [Haskell-cafe] help me evangelize haskell.

2010-09-07 Thread Don Stewart
That's a separate module, based on System.Process -- http://code.haskell.org/~dons/code/cpuperf/Process.hs ckkashyap: Hi Dan, This presentation is really nice. I went over it a couple of times and I think this ppt will help me try to use Haskell for things that I usually use Perl for :)

  1   2   3   4   >