Re: [Haskell-cafe] need help with understanding expression

2012-11-17 Thread MigMit
Отправлено с iPhone 17.11.2012, в 11:19, damodar kulkarni kdamodar2...@gmail.com написал(а): In the second case, why the GHC doesn't give something like? ([Char] (a - t), Num a) = t Because Num is a class of types, while String is a type. In other words, in the expression 3 a ghc doesn't

Re: [Haskell-cafe] I killed performance of my code with Eval and Strategies

2012-11-17 Thread Janek S.
Just another definition of calculateSeq: calculateSeq = zipWith ($) (cycle [sin,cos]) . map sqrt This is just slightly slower than my implementation. I came up with a better implementation of parallel function: calculatePar2 :: [Double] - [Double] calculatePar2 xss = runEval $ concat

[Haskell-cafe] List all multiply/add combinations

2012-11-17 Thread Rune Harder Bak
Given a list of numbers of fixed length I need to list all possible values (and the associated computation) you get by inserting +,-,*,/ between the numbers, and also set parentheses where you please. It shouldn't list computations with unnecessary parentheses. Example list of length 3 [a,b,c] and

[Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Nicolas Trangez
All, I've been working on a server implementation of an existing networking protocol. The protocol uses magic constants in some places (e.g. to tag message types), as well as bitfields, or a combination of both packed in a single value. I created data types for both the identifiers as well as

Re: [Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Roman Cheplyaka
Hi Nicolas, The simplest approach would be to use the standard (derived) Enum instance that would be used for enumerations (like [Flag1..]), and have your own functions to convert to/from magic constants. Roman * Nicolas Trangez nico...@incubaid.com [2012-11-17 15:44:57+0100] All, I've been

[Haskell-cafe] Parsing different types, same typeclass

2012-11-17 Thread José Lopes
Hello everyone, I was wondering if you could help me! So, I have a typeclass Action which defines method run: class Action a where run :: a - Int and two data types that are instances of this typeclass: data A = A Int deriving (Read, Show) instance Action A where run (A n) =

Re: [Haskell-cafe] List all multiply/add combinations

2012-11-17 Thread timothyhobbs
This smells like homework to me, which isn't a bad thing, it will however change the way I answer you. Please look at http://hackage.haskell.org/packages/archive/base/latest/doc/ html/Data-List.html#v:permutations and show us your attempts to use this function. Timothy -- Původní

Re: [Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Nicolas Trangez
On Sat, 2012-11-17 at 16:52 +0200, Roman Cheplyaka wrote: Hi Nicolas, The simplest approach would be to use the standard (derived) Enum instance that would be used for enumerations (like [Flag1..]), and have your own functions to convert to/from magic constants. Sure, but that kind-of

Re: [Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Herbert Valerio Riedel
Nicolas Trangez nico...@incubaid.com writes: On Sat, 2012-11-17 at 16:52 +0200, Roman Cheplyaka wrote: Hi Nicolas, The simplest approach would be to use the standard (derived) Enum instance that would be used for enumerations (like [Flag1..]), and have your own functions to convert to/from

Re: [Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Nicolas Trangez
On Sat, 2012-11-17 at 16:27 +0100, Herbert Valerio Riedel wrote: what do you hope to gain from making your flags type an instance of the Enum class? Among others, the ability to list all flags using [Flag1 ..] How is this handled for libraries wrapping C libs which use some bitset structure?

Re: [Haskell-cafe] Custom Enum instance with non-consecutive indices

2012-11-17 Thread Roman Cheplyaka
* Nicolas Trangez nico...@incubaid.com [2012-11-17 16:23:28+0100] On Sat, 2012-11-17 at 16:52 +0200, Roman Cheplyaka wrote: Hi Nicolas, The simplest approach would be to use the standard (derived) Enum instance that would be used for enumerations (like [Flag1..]), and have your own

[Haskell-cafe] Call for Participation: Programming Languages Mentoring Workshop - a POPL workshop.

2012-11-17 Thread Gareth Smith
Apologies for any duplicates: CALL FOR PARTICIPATION SIGPLAN Programming Languages Mentoring Workshop, Rome Tuesday January 22, 2013 Co-located with POPL 2013 PLMW web page: http://www.doc.ic.ac.uk/~gds/PLMW/index.html After the resounding success of the first Programming Languages

Re: [Haskell-cafe] List all multiply/add combinations

2012-11-17 Thread Rune Harder Bak
It might be rare that a real world problem can be formulated as such a simple mathematical challenge, so I can't blame you for thinking about home work. I did too. Actually it's part of a logic puzzle I'm implementing. Attacking the problem textually, I can treat the list of infix operators as

Re: [Haskell-cafe] List all multiply/add combinations

2012-11-17 Thread Artyom Kazak
Instead of attacking the problem textually, try to create a datatype which would describe your expressions, then generate all values of this datatype, filter those you don’t need, and convert the rest into Strings. Currently your expressions are represented by “String” — conversion is very

Re: [Haskell-cafe] List all multiply/add combinations

2012-11-17 Thread Artyom Kazak
Sorry! I replied without reading your message properly. I could then work directly with parsing trees, and generate all binary trees of fixed lengths. But most of them would be unnecessary, so it seems like I'm attacking it from the wrong angle. They won’t be unnecessary if you generate them

Re: [Haskell-cafe] How to determine correct dependency versions for a library?

2012-11-17 Thread Ganesh Sittampalam
On 09/11/2012 18:35, Clark Gaebel wrote: I think we just use dependencies different things. This is a problem inherent in cabal. When I (and others) specify a dependency, I'm saying My package will work with these packages. I promise. When you (and others) specify a dependency, you're

Re: [Haskell-cafe] List all multiply/add combinations

2012-11-17 Thread Artyom Kazak
The following algorithm generates all possible expressions and throws away most of unnecessary duplicates. import qualified Data.Map as M data Expr = Num Int | Add Expr Expr | Sub Expr Expr | Mul Expr Expr | Div Expr Expr Rendering function is

Re: [Haskell-cafe] List all multiply/add combinations

2012-11-17 Thread Artyom Kazak
Indentation messed up… I have pasted the code here: http://hpaste.org/77864 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Parsing different types, same typeclass

2012-11-17 Thread Stephen Tetley
Being concrete, all you can do is: parseAction :: String - Either A B parseAction str | (A `isPrefixOf` str = Left $ read str | (B `isPrefixOf` str = Right $ read str parseAction :: String - Int parseAction str | (A `isPrefixOf` str = run $ (read str :: A) | (B `isPrefixOf`

Re: [Haskell-cafe] Parsing different types, same typeclass

2012-11-17 Thread José A. Lopes
Hey Stephen, Thank you for the reply! Can you elaborate on how I can use existentials? I always up for learning new (Haskell) stuff :) Cheers, José On 18-11-2012 00:19, Stephen Tetley wrote: Being concrete, all you can do is: parseAction :: String - Either A B parseAction str | (A

Re: [Haskell-cafe] How to determine correct dependency versions for a library?

2012-11-17 Thread Michael Orlitzky
Replying somewhere random in the thread. Linux distributions have to solve this same problem. We first need to decide what Hackage's function is supposed to be: (1) A dumb repository to host Haskell code (2) A collection of Haskell packages that work together In reality it's (1), but the

Re: [Haskell-cafe] I killed performance of my code with Eval and Strategies

2012-11-17 Thread Bertram Felgenhauer
Dear Janek, I am reading Simon Marlow's tutorial on parallelism and I have problems with correctly using Eval monad and Strategies. I *thought* I understand them but after writing some code it turns out that obviously I don't because parallelized code is about 20 times slower. Here's a short

Re: [Haskell-cafe] need help with understanding expression

2012-11-17 Thread Albert Y. C. Lai
On 12-11-17 02:19 AM, damodar kulkarni wrote: Let's see tthis: Prelude :t 3 a 3 a :: (Num ([Char] - t)) = t No complaint from GHC; but now see this: Prelude :t a 3 interactive:1:0: Couldn't match expected type `t1 - t' against inferred type `[Char]' In the expression: a

Re: [Haskell-cafe] Parsing different types, same typeclass

2012-11-17 Thread Chris Wong
Hello José, So, I have a typeclass Action which defines method run: class Action a where run :: a - Int (snipped) Now, I want to parse either A or B from a String. I was thinking about something like this... parseAction :: (Action a, Read a) = String - a parseAction str | (A