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 :: Integer - Integer
fibWithFix = fix fibBase
```

I can say `fibBase` is free of recursion, despite the facts that apparently
it uses a name `fib` on RHS which it binds on the LHS, and that the entire
structure seems very similar to the recursive version of `fib` .



2013/6/16 Takayuki Muranushi muranu...@gmail.com

 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 recipe found here:

 http://lambda-the-ultimate.org/node/4290

 ~~~
 Given a function that recurses on itself, do a partial CPS transform so
 that it only ever recurses on itself with tail calls. Then, convert the
 recursive calls to codata returns, so that the function either returns
 TheAnswer or StillWorking with enough parameters to describe the recursive
 call / continuation state. This codata can be built with an unfold and can
 be collapsed back down to the final answer with a fold.
 ~~~


 https://github.com/nushio3/practice/blob/master/lens/banana/CollatzTest.hs
 https://github.com/nushio3/practice/blob/master/lens/banana/FibTest.hs

 I find it difficult to understand the terminology, and the above attempts
 are only halfway done. I guess ( TheAnswer or StillWorking ) structure is
 the one found in iteratee/enumeratee. But I don't know how to build a
 codata with unfold.

 I'd appreciate any advice.

 Best,

 --
 Takayuki MURANUSHI
 The Hakubi Center for Advanced Research, Kyoto University
 http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html




-- 
Takayuki MURANUSHI
The Hakubi Center for Advanced Research, Kyoto University
http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 bytes allocated in the heap
 228,827,904 bytes copied during GC
 104,048 bytes maximum residency (6 sample(s))
  24,408 bytes maximum slop
   2 MB total memory in use (0 MB lost due to fragmentation)
...

 $ while pidof test /dev/null; do ps -o rss= -p $(pidof test); sleep 1; done 
 | tail
32056
32408
32832
33264
33684
34100
34560
34900
35384
35816 # ~ 35MB

Thanks!
~dsouza

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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.
Here'shttp://www.haskell.org/ghc/docs/7.4.2/html/users_guide/type-families.html#data-family-overlapthe
GHC page on it. With type families you can do overlap, but in that
case, the result of unification must be the same. So basically :

 T a a === T a b (with b set to a)

whereas the intuitive way of doing Find requires a way of differentiating
between these two cases.


On Wed, Feb 27, 2013 at 4:33 PM, Dmitry Kulagin dmitry.kula...@gmail.comwrote:

 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 :: Nat) (xs :: [Ty]) :: Ty

 But it is not very convenient to identify struct's fields using naturals,
 and I wanted to change Ty definition to:

  data Ty = TInt | TBool | TStruct Symbol [(Symbol, Ty)]

 It is much closer to how C-struct looks, but I was unable to implement
 required type function:

   type family Find (s :: Symbol) (xs :: [(Symbol,Ty)]) :: Ty

 Which just finds a type in a associative list.

 Could someone give me a hint, how to do it?
 Or perhaps, is it just impossible thing to do?

 Thanks!


 ___
 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] 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 function using type
families. It will be possible with new closed type familes (they are
in GHC head already).

But for now it's possible to use overlapping instances and fundeps.
Implementation of type level equality is simple and it's only
instances which need ovelap.

-- | Type class for type equality.
class  TypeEq (a :: α) (b :: α) (eq :: Bool) | a b - eq
instance   TypeEq a a True
instance eq ~ False = TypeEq a b eq


Implementation of lookup by key is relatively straightforward. Note
that it doesn't check that key is unique.

data k : v
infix 6 :

-- | Lookup type for given key
class TyLookup (map :: [*]) (k :: *) (v :: *) | map k - v where

class TyLookupCase (map :: [*]) (k :: *) (v :: *) (eq :: Bool) | map k
eq - v where

instance ( TypeEq k k' eq
 , TyLookupCase (k : v ': xs) k' v' eq
 ) = TyLookup  (k : v ': xs) k' v' where

instance TyLookupCase (k  : v  ': xs) k v True  where
instance TyLookup xs k v = TyLookupCase (k' : v' ': xs) k v False where

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
 , HRLabelSet' l1 l2 leq r
 ) = HRLabelSet (LVPair l1 v1 ': LVPair l2 v2 ': r)

so the usage of the extension is unavoidable for my purposes?

Thank you!


On Wed, Feb 27, 2013 at 12:28 PM, o...@okmij.org wrote:


 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 associative list.

 HList also implemented records with named fields. Indeed, you need a
 type-level lookup in an associative list, and for that you need type
 equality. (The ordinary List.lookup has the Eq constraint, doesn't
 it?)

 Type equality can be implemented with type functions, right now.
 http://okmij.org/ftp/Haskell/typeEQ.html#TTypeable

 (That page also defined a type-level list membership function).






___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
  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 function using type
 families. It will be possible with new closed type familes (they are
 in GHC head already).

 But for now it's possible to use overlapping instances and fundeps.
 Implementation of type level equality is simple and it's only
 instances which need ovelap.

 -- | Type class for type equality.
 class  TypeEq (a :: α) (b :: α) (eq :: Bool) | a b - eq
 instance   TypeEq a a True
 instance eq ~ False = TypeEq a b eq


 Implementation of lookup by key is relatively straightforward. Note
 that it doesn't check that key is unique.

 data k : v
 infix 6 :

 -- | Lookup type for given key
 class TyLookup (map :: [*]) (k :: *) (v :: *) | map k - v where

 class TyLookupCase (map :: [*]) (k :: *) (v :: *) (eq :: Bool) | map k
 eq - v where

 instance ( TypeEq k k' eq
  , TyLookupCase (k : v ': xs) k' v' eq
  ) = TyLookup  (k : v ': xs) k' v' where

 instance TyLookupCase (k  : v  ': xs) k v True  where
 instance TyLookup xs k v = TyLookupCase (k' : v' ': xs) k v False where

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

f :: TypeEq Int Int True = Int
f = 1

When I try to invoke f, I get overlapping instances error:
Overlapping instances for TypeEq * Int Int 'True
  arising from a use of `f'
Matching instances:
  instance TypeEq k a a 'True -- Defined at Test.hs:14:24
  instance eq ~ 'False = TypeEq k a b eq -- Defined at Test.hs:16:10

Thanks.


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
  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 function using type
 families. It will be possible with new closed type familes (they are
 in GHC head already).

 But for now it's possible to use overlapping instances and fundeps.
 Implementation of type level equality is simple and it's only
 instances which need ovelap.

 -- | Type class for type equality.
 class  TypeEq (a :: α) (b :: α) (eq :: Bool) | a b - eq
 instance   TypeEq a a True
 instance eq ~ False = TypeEq a b eq


 Implementation of lookup by key is relatively straightforward. Note
 that it doesn't check that key is unique.

 data k : v
 infix 6 :

 -- | Lookup type for given key
 class TyLookup (map :: [*]) (k :: *) (v :: *) | map k - v where

 class TyLookupCase (map :: [*]) (k :: *) (v :: *) (eq :: Bool) | map k
 eq - v where

 instance ( TypeEq k k' eq
  , TyLookupCase (k : v ': xs) k' v' eq
  ) = TyLookup  (k : v ': xs) k' v' where

 instance TyLookupCase (k  : v  ': xs) k v True  where
 instance TyLookup xs k v = TyLookupCase (k' : v' ': xs) k v False where

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 b False
instance eq ~ False = TypeEq a b eq


You need to add pragma {-# LANGUAGE OverlappingInstances #-}
to the file where instances defined. Without it GHC will complain
about overlap and unlike other extensions won't recommend pragma

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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,

 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

  You need to add pragma {-# LANGUAGE OverlappingInstances #-}
 to the file where instances defined. Without it GHC will complain
 about overlap and unlike other extensions won't recommend pragma

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 + 1 into the mutable cell. readIORef just reports back a pointer. 
modifyIORef just calls readIORef and writeIORef. No evaluation throughout.


modifyIORef incr where

incr !x = x + 1

does not make a difference because it is just writeIORef r (incr x)), 
i.e., simply stores a pointer to the expression (thunk) incr x into 
the mutable cell. The whole process doesn't even care about how many 
bangs are in incr.


(It is illuminating to consider how const True (incr x) does not 
evaluate x. A pointer to True and a pointer to incr x are passed to 
const, then const throws away the latter without even looking. See also 
const True undefined. One day, you will thank writeIORef r 
undefined; I certainly did.)


Same for both Data.STRef.Strict and Data.STRef.Lazy. They do not mean 
what you think. Here is what they mean:


Data.STRef.Strict means what Control.Monad.ST.Strict means
Data.STRef.Lazy means what Control.Monad.ST.Lazy means

Control.Monad.ST.Strict means that the following hangs:

x = head (runST list) where
  list :: ST s [Bool]
  list = do {xs - list; return (True : xs)}

Control.Monad.ST.Lazy means that the above terminates and gives the 
answer True.


(Up to this point, same story for Control.Monad.State.Strict and 
Control.Monad.State.Lazy.)


I still have not understood Control.Monad.ST.Lazy enough to articulate 
its full semantics, but I have some more examples to show what it does:


http://hpaste.org/63925

By understanding what Lazy in Control.Monad.ST.Lazy means, you also 
see what Strict does *not* mean.


In IO or Control.Monad.ST.Strict, use

  let y = x+1 in y `seq` write[IO/ST]Ref r y

to expedite the evaluation of x+1. Using the same idea, you may write 
your own modify[IO/ST]RefNOW to evaluate while updating.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 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
 + 1 into the mutable cell. readIORef just reports back a pointer.
 modifyIORef just calls readIORef and writeIORef. No evaluation throughout.

 modifyIORef incr where

 incr !x = x + 1

 does not make a difference because it is just writeIORef r (incr x)),
 i.e., simply stores a pointer to the expression (thunk) incr x into the
 mutable cell. The whole process doesn't even care about how many bangs are
 in incr.

 (It is illuminating to consider how const True (incr x) does not evaluate
 x. A pointer to True and a pointer to incr x are passed to const, then
 const throws away the latter without even looking. See also const True
 undefined. One day, you will thank writeIORef r undefined; I certainly
 did.)

 Same for both Data.STRef.Strict and Data.STRef.Lazy. They do not mean what
 you think. Here is what they mean:

 Data.STRef.Strict means what Control.Monad.ST.Strict means
 Data.STRef.Lazy means what Control.Monad.ST.Lazy means

 Control.Monad.ST.Strict means that the following hangs:

 x = head (runST list) where
   list :: ST s [Bool]
   list = do {xs - list; return (True : xs)}

 Control.Monad.ST.Lazy means that the above terminates and gives the answer
 True.

 (Up to this point, same story for Control.Monad.State.Strict and
 Control.Monad.State.Lazy.)

 I still have not understood Control.Monad.ST.Lazy enough to articulate its
 full semantics, but I have some more examples to show what it does:

 http://hpaste.org/63925

 By understanding what Lazy in Control.Monad.ST.Lazy means, you also see
 what Strict does *not* mean.

 In IO or Control.Monad.ST.Strict, use

   let y = x+1 in y `seq` write[IO/ST]Ref r y

 to expedite the evaluation of x+1. Using the same idea, you may write your
 own modify[IO/ST]RefNOW to evaluate while updating.


 ___
 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] 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 AM, Branimir Maksimovic bm...@hotmail.com wrote:

Thanks ! Should I contribute your version on shootout site?
Do whatever you like with it. ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 c++
 On my machine Haskell runs 52 secs while c++ 30 secs.


Did you compile with -O2 -fllvm?

On my machine:

C++ 28 sec
Mine -O2 -fllvm 37 sec
Yours -O2 -fllvm 41 sec
Mine -O2 48 sec
Yours -O2 54 sec

My version of your Haskell code is here: http://hpaste.org/78705
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help optimize fannkuch program

2012-12-03 Thread Branimir Maksimovic

Thanks. Your version is much faster.Yes, I have compiled with ghc --make -O2 
-fllvm -optlo-O3 -optlo-constprop fannkuchredux4.hs(there is bug in ghc 7.4.2 
regarding llvm 3.1  which is circumvented with constrprop)
results: yours:bmaxa@maxa:~/shootout/fannkuchredux$ time ./fannkuchredux4 
123968050Pfannkuchen(12) = 65
real0m39.200suser0m39.132ssys 0m0.044s
mine:bmaxa@maxa:~/shootout/fannkuchredux$ time ./fannkuchredux 
123968050Pfannkuchen(12) = 65
real0m50.784suser0m50.660ssys 0m0.092s
Seems that you machine is faster than mine and somewhat better for executing 
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...@hotmail.com wrote:

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 comparisonwith c++ On my 
machine Haskell runs 52 secs while c++ 30 secs.
Did you compile with -O2 -fllvm?

On my machine:
C++ 28 secMine -O2 -fllvm 37 secYours -O2 -fllvm 41 secMine -O2 48 secYours -O2 
54 sec
My version of your Haskell code is here: http://hpaste.org/78705
  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 symbol table
while at the same time associating the function name
to the expression that represents the function body.
Naturally, the expression needs to be evaluated, thus
the circularity and the DoRec extension as in the
following code:

evalM (DefnStx str body) =
do rec addBindM str expr
   expr - evalM body
   return expr

I am using the state monad so I don't have to manually
pass the symbol table around all the time. Now, there are
two things: the first is that this works with the state monad
without any problem:

type InterpreterM a = StateT ExprEnv a

The second is that, similarly to the previous email, when I use
the state monad transformer the program no longer works.
With the IO monad as the wrapped monad the program
crashed with the MVar... error message.

In the new code I am no longer using the IO monad. Instead, I
am using the Error monad. So I have the following definition

type InterpreterM a = StateT ExprEnv (Either String) a

With this definition, the program enters an infinite loop. I am
not even using the throwError and catchError functions
yet! I just change the definition of InterpreterM, which is the
evaluator monad.

What can I do ?

Best regards,
José

On 24-10-2012 01:01, Joey Adams wrote:

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 code to use the StateT monad transformer wrapped around
IO monad and runStateT.
And this change introduced the error message.

BTW I am using DoRec extension, maybe it is the source of the problem, but I
don't know.

See if you can reproduce the problem using a small code sample.  The
problem is likely that your program is trying to use a state value
that hasn't been produced yet.

DoRec uses fixIO for the IO monad.  fixIO passes a callback its own
return value.  It's not magic; it only works if the thunk is not
forced within the callback.

Take a look at how fixIO is implemented:

 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/System-IO.html#fixIO


--
José António Branquinho de Oliveira Lopes
Instituto Superior Técnico
Technical University of Lisbon


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 code to use the StateT monad transformer wrapped around
 IO monad and runStateT.
 And this change introduced the error message.

 BTW I am using DoRec extension, maybe it is the source of the problem, but I
 don't know.

See if you can reproduce the problem using a small code sample.  The
problem is likely that your program is trying to use a state value
that hasn't been produced yet.

DoRec uses fixIO for the IO monad.  fixIO passes a callback its own
return value.  It's not magic; it only works if the thunk is not
forced within the callback.

Take a look at how fixIO is implemented:


http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/System-IO.html#fixIO

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 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 functional programming, especially
 Haskell. FP is my true passion and I'm another dreamer trying to land the
 job he loves.

 In a nutshell I'm looking for every possibility to do Haskell/functional
 programming in Europe/North Europe. I'm throwing this stone into this pond
 because life has endless possibilities, who knows? :)

 A disclaimer, though: I'm not an expert Haskeller, but I'm very passionate
 about technology and I love learning (I've obviously already read LYAH and
 RWH). You can find more information about me (including my CV if interested)
 here:

 www.alfredodinapoli.com

 Oh! One last thing! I would be very grateful to everyone willing to spent
 two minutes of his time giving me any kind of suggestion about the FP job
 world or how to prepare/improve myself for the foreseeable future.

 Thanks again,
 and sorry for the OT/spammish plug.

 Humbly,
 Alfredo Di Napoli

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



-- 
Eugene Kirpichov
http://www.linkedin.com/in/eugenekirpichov
We're hiring! http://tinyurl.com/mirantis-openstack-engineer

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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, functions
 would have a type signature of Source, Sink, or Conduit. For example:

    sourceFile :: MonadResource m = FilePath - Source m ByteString

 I think most people can guess at what this function does: it produces
 a stream of ByteStrings, which are read from the given file.

 Now the trick: Source (and Sink and Conduit) are all type synonyms
 wrapping around the same type, Pipe. Ideally, we'd like to be able to
 reuse functions like sourceFile in other contexts, such as producing a
 Conduit that calls sourceFile[1]. However, the type synonym Source
 over-specifies some of the type parameters to Pipe, and therefore
 `sourceFile` can't be used directly to create a Conduit[2].

 To get around this whole problem, I've added a number of type synonyms
 with rank-2 types, that don't over-specify. You can see the type
 synonyms here[3], and more explanation of the problem here[4]. So my
 question is: can anyone come up with better names for these synonyms?
 Just to summarize here:

 * All of the generalized types start with a G, e.g., Source becomes GSource.
 * For Sinks and Conduits, if leftovers are generated, there's an L
 after the G (e.g., GLSink).
 * For Sinks and Conduits which consume all of their input and then
 return the upstream result, we tack on an Inf for Infinite (e.g.,
 GInfConduit, GLInfSink).

 I think these names are relatively descriptive, and certain `GSink
 ByteString m Int` is easier to follow than `Pipe l ByteString o u m
 Int`, but I was wondering if anyone had some better recommendations.

I ran into this problem myself with my implementation that used 7 type
parameter (the extra parameter wrt to conduit was used by Defer), and I
couldn't think of any satisfactory solution.

The dilemma here is:

 - exposing the full `Pipe` type as the primary API would be really confusing
   for new users
 - creating a bunch of type synonyms adds a lot of conceptual overhead, and
   it's actually a leaky abstraction, because `Pipe` will probably be shown in
   error messages, and appears in the signatures of basic combinators

In the end, I gave up the 2 non-essential parameters, built the corresponding
lost features on top of `Pipe` using newtypes, and decided to expose a
5-parameter `Pipe` type with no universally quantified synonyms.

I'm not sure how easy this Pipe type is to understand, but at least all
parameters have a clear meaning that can be explained in the documentation,
whereas the `l` parameter is sort of a hack (like my 'd' parameter).

BR,
Paolo

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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: 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:

    sourceFile :: MonadResource m = FilePath - Source m ByteString

 I think most people can guess at what this function does: it produces
 a stream of ByteStrings, which are read from the given file.

 Now the trick: Source (and Sink and Conduit) are all type synonyms
 wrapping around the same type, Pipe. Ideally, we'd like to be able to
 reuse functions like sourceFile in other contexts, such as producing a
 Conduit that calls sourceFile[1]. However, the type synonym Source
 over-specifies some of the type parameters to Pipe, and therefore
 `sourceFile` can't be used directly to create a Conduit[2].

 To get around this whole problem, I've added a number of type synonyms
 with rank-2 types, that don't over-specify. You can see the type
 synonyms here[3], and more explanation of the problem here[4]. So my
 question is: can anyone come up with better names for these synonyms?
 Just to summarize here:

 * All of the generalized types start with a G, e.g., Source becomes GSource.
 * For Sinks and Conduits, if leftovers are generated, there's an L
 after the G (e.g., GLSink).
 * For Sinks and Conduits which consume all of their input and then
 return the upstream result, we tack on an Inf for Infinite (e.g.,
 GInfConduit, GLInfSink).

 I think these names are relatively descriptive, and certain `GSink
 ByteString m Int` is easier to follow than `Pipe l ByteString o u m
 Int`, but I was wondering if anyone had some better recommendations.

 I ran into this problem myself with my implementation that used 7 type
 parameter (the extra parameter wrt to conduit was used by Defer), and I
 couldn't think of any satisfactory solution.

 The dilemma here is:

  - exposing the full `Pipe` type as the primary API would be really confusing
   for new users
  - creating a bunch of type synonyms adds a lot of conceptual overhead, and
   it's actually a leaky abstraction, because `Pipe` will probably be shown in
   error messages, and appears in the signatures of basic combinators

 In the end, I gave up the 2 non-essential parameters, built the corresponding
 lost features on top of `Pipe` using newtypes, and decided to expose a
 5-parameter `Pipe` type with no universally quantified synonyms.

 I'm not sure how easy this Pipe type is to understand, but at least all
 parameters have a clear meaning that can be explained in the documentation,
 whereas the `l` parameter is sort of a hack (like my 'd' parameter).

I think even five parameters are too many. The original conduit types
had either 2 or 3 parameters, and each one was essential and easily
explainable. I realize that- for now- type synonyms will not help at
all with error messages (which I consider a serious problem), but at
least normal API functions like sourceFile will get helpful
signatures.

One idea that I've toyed around with- but not really pursued- is
creating actual newtypes for Source, Conduit, and Sink, and using
Chris's typeclass approach for when we want general functions. After
some basic fiddling, the typeclasses just seem to make everything more
difficult to work with.

You're correct by the way that we need a lot of type synonyms (I got 9
of them). But I still think it helps with the overhead instead of
hurting. While it may be important for some cases to understand the
different between GSink and GLSink, for most use cases simply knowing
oh, this thing takes a stream of `a` and gives a single result of
`b` is sufficient. But I think only real world usage is going to help
us determine the best approach here.

Michael

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 think it does - because file names are  state/T/*.log   and so on?


The function 'openLocalState' in AcidState uses the name of the passed
in state type to locate the log files on disk.

So as long as you always call 'openLocalState' with types of the same
name to represent the same state you'll be fine - this is why it is
safe to rename your old type, because you call 'openLocalState' with
the new type.

Alternatively, you can call 'openLocalStateFrom', which doesn't base
anything on names of types (you can tell because there is no
'Typeable' constraint on its arguments).

Antoine

 J.W.



 ___
 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] 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], you need to
 increase the version of your data type (e.g. change that zero to one).

Thanks - which zero? (there are two of them.)

and how does it play together with Data.Acid?

Can I really rename  old.T = new.T_orig ?
It looks as if then tries to load the wrong acid-state snapshot.

Best - J.W.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 of the new version of your data type,
akin to releasing a new version of a library.

 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.

HTH,

-- 
Felipe.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 deriveSafeCopy's documentation [1], you need to
increase the version of your data type (e.g. change that zero to one).

HTH,

[1] 
http://hackage.haskell.org/packages/archive/safecopy/0.6.1/doc/html/Data-SafeCopy.html#v:deriveSafeCopy

-- 
Felipe.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 first try (solution is ok) was to do it as haskeller as possible,
trying to overcome my imperative mind.
But it did bad at performance (0.30 secs of runtime, 4.6 mb of memory):

-- code start
import Data.Char (toLower)

main = getContents=  mapM_ (putStrLn . toStr . isTautogram . words)
. takeWhile (/= *) . lines


That's still imperative! :-)

How about 'interact' and using 'unlines' instead of 'putStrLn' ?



toStr :: Bool -  [Char]


You may want to write String instead of [Char] for clarity.


toStr True = Y
toStr False = N

isTautogram :: [[Char]] -  Bool
isTautogram (x:[]) = True


I assume this case is not necessary, since  all [] == True  anyway.


isTautogram (x:xs) = all ((== firstChar) . toLower . head) xs
 where firstChar = toLower . head $ x


It is maybe more elegant, not to compare all words with the first one, 
but to compare adjacent words in the list:


all (zipWith (...) xs (drop 1 xs))



Note that the only thing that changed between the two tries was the main-loop.
The second version runs faster (got 0.11 secs) and with less memory (3.6 mb)

Can someone explain to me what is really going on?
Maybe pointing out how I can achieve these optimizations using
profiling information...


Interesting observation. I do not see a problem quickly.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 = interact' $ unlines' . solveAll . takeWhile ((/= '*') . head') . lines'

solveAll :: [String'] - [String']
solveAll = map $ toStr . solve

toStr :: Bool - String'
toStr True = makeString' Y
toStr False = makeString' N

solve :: String' - Bool
solve = isTautogram . words'

isTautogram :: [String'] - Bool
isTautogram (x:xs) = all ((== firstChar) . normalizeHead) xs
where firstChar = normalizeHead x

normalizeHead :: String' - Char
normalizeHead = toLower . head'

-- optimizations
type String' = BS.ByteString
interact' = BS.interact
unlines' = BS.unlines
lines' = BS.lines
head' = BS.head
words' = BS.words
makeString' = BS.pack
-- code end

Thanks all,
Thiago.

2011/8/11 Henning Thielemann schlepp...@henning-thielemann.de:
 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 first try (solution is ok) was to do it as haskeller as possible,
 trying to overcome my imperative mind.
 But it did bad at performance (0.30 secs of runtime, 4.6 mb of memory):

 -- code start
 import Data.Char (toLower)

 main = getContents=  mapM_ (putStrLn . toStr . isTautogram . words)
 . takeWhile (/= *) . lines

 That's still imperative! :-)

 How about 'interact' and using 'unlines' instead of 'putStrLn' ?


 toStr :: Bool -  [Char]

 You may want to write String instead of [Char] for clarity.

 toStr True = Y
 toStr False = N

 isTautogram :: [[Char]] -  Bool
 isTautogram (x:[]) = True

 I assume this case is not necessary, since  all [] == True  anyway.

 isTautogram (x:xs) = all ((== firstChar) . toLower . head) xs
     where firstChar = toLower . head $ x

 It is maybe more elegant, not to compare all words with the first one, but
 to compare adjacent words in the list:

 all (zipWith (...) xs (drop 1 xs))


 Note that the only thing that changed between the two tries was the
 main-loop.
 The second version runs faster (got 0.11 secs) and with less memory (3.6
 mb)

 Can someone explain to me what is really going on?
 Maybe pointing out how I can achieve these optimizations using
 profiling information...

 Interesting observation. I do not see a problem quickly.

 ___
 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] 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 results are:

Main p [2*3,4/2]
6


I'm not so sure, if i have to modify the caller function only, or i
have to modify both the caller function and the exact function that
makes the parsing?

2011/6/25 Jack Henahan jhena...@uvm.edu:
 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 
 sure if that's the effect you're after.

 http://hpaste.org/48324
 Edited code (really just indentation changes and the change from p [] = [] to 
 p [] = 0)

 On Jun 25, 2011, at 3:19 PM, Stoyan Peev wrote:

 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 still breaking down somewhere ...



 2011/6/25 Daniel Patterson lists.hask...@dbp.mm.st:
 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 only 
 my guess, based on the assumption that the whitespace is being converted to 
 a syntax with explicit semilcolon line terminations.

 now, looking at the actual code, the type of the parse function is [a] - 
 [a]. This means that you can parse a list of anything into a list of 
 anything, which doesnt make much sense. This should probably be [String] - 
 [String]  (you are parsing a list of strings to a list of strings, yes?). 
 Now the base case of parse (the first case) makes sense, but look at the 
 second case. parse is being given a list of elements (which you have used 
 pattern matching to decompose, but the whole argument, (x:xs), is a list of 
 elements). You are then passing that, unchanged, to eval. This means that 
 eval must take the same type. Does it? how would you apply eval to each 
 element in that list, instead of just applying it to the whole list?

 On Jun 24, 2011, at 4:31 PM, Stoyan Peev wrote:

 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 from the compiler:

 ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;',
 possibly due to bad layout)


 On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson
 lists.hask...@dbp.mm.st wrote:
 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 order functions in your class - would any of the common ones 
 (filter, map, foldr) be helpful here? Would any encapsulate what you are 
 trying to do?

  If you include these kinds of things, I think you'll find this community 
 to be very helpful; without that (showing what your thought process is, 
 why it isn't working, what seems confusing about what the haskell 
 compiler is telling you, etc), you are not going to get help here. People 
 here are very friendly and willing to help people learn; this is not a 
 place to come to get an assignment finished :)

 Also, could you put the library you are using (I'm assuming that this is 
 provided by your university) and the code on somewhere like hpaste.org, 
 so that the formatting is not messed up by email, and it is syntax 
 highlighted?

 On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote:

 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 _expression_ - calculate
 this _expression_. The string result becomes part of the list-result.
 If the _expression_ contains a variable which is not assigned value,
 the result is displayed undefined.
 - If the string has the form- Name = value calculated from the last
 _expression_ is assigned to the variable with the corresponding name
 in the list, 

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 should have type p :: [String] - [Int].

Now the base case is obvious - if you are given an empty list of strings, then 
you should give back an empty list of results. 

The recursive case is a little more complicated - the idea with simple 
recursion is that the recursive case should eventually land you at the base 
case, which will stop the recursion. With lists, this usually means that each 
application of the recursive case should call itself on the rest of the list, 
and somehow process the first element of the list (it doesnt have to be this 
way, but often is).

So in your case, the recursive case should be: evaluate the first element of 
the list, and then call the whole function on the rest of the list. You can 
check this mentally by using a couple examples. In the case of a one element 
list, this means that it will evaluate the first (and only) element of the 
list, and then call itself on the rest of the list, which is an empty list, 
which is the bottom case and therefore ends the recursion. On a two element 
list, this can be checked as well. 

Now the types should be your best friend. You know that you want:

p :: [String] - [Int] 

That is from the problem statement. 

So you write the base case first:

p [] = []

Now for the recursive case, you know you want to eval the first element, and 
then call the function on the rest of the list. But since you need to return a 
list eventually, then you need to return a list in this function. You know that 
calling the function recursively will result in a list (the type guarantees 
that), so if you've evaluated the first element of a list, resulting in an Int, 
and you have a list of Int's that is the rest of the list, how do you combine 
those? Well, put the element at the beginning of the list!

p (x:xs) = (eval p) : (p xs)


Now this is a really really common pattern - do the same thing to every element 
of a list. The first thing in haskell to do if you think that what you are 
doing might already exist in some generalized form is to try to describe what 
the function is that you want. So in our case, you want a function that takes 
another function and applies it to every element in the list. This function 
would have type:

(a - b) - [a] - [b]

In your case the (a - b) is String - Int (the function eval), the [a] is 
[String], [b] is [Int]. Now if you take this and search on Hoogle (a haskell 
search engine: 
http://haskell.org/hoogle/?hoogle=%28a+-%3E+b%29+-%3E+%5Ba%5D+-%3E+%5Bb%5D ), 
the first result is a function called map, which does exactly what you want. So 
you can actually write your whole p function as:

p :: [String] - [Int]
p xs = map eval xs

Or, if you are okay with partial application, this is equivalent to:
p :: [String] - [Int]
p = map eval

On Jun 25, 2011, at 3:56 PM, Jack Henahan wrote:

 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 
 sure if that's the effect you're after.
 
 http://hpaste.org/48324
 Edited code (really just indentation changes and the change from p [] = [] to 
 p [] = 0)
 
 On Jun 25, 2011, at 3:19 PM, Stoyan Peev wrote:
 
 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 still breaking down somewhere ...
 
 
 
 2011/6/25 Daniel Patterson lists.hask...@dbp.mm.st:
 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 only 
 my guess, based on the assumption that the whitespace is being converted to 
 a syntax with explicit semilcolon line terminations.
 
 now, looking at the actual code, the type of the parse function is [a] - 
 [a]. This means that you can parse a list of anything into a list of 
 anything, which doesnt make much sense. This should probably be [String] - 
 [String]  (you are parsing a list of strings to a list of strings, yes?). 
 Now the base case of parse (the first case) makes sense, but look at the 
 second case. parse is being given a list of elements (which you have used 
 pattern matching to decompose, but the whole argument, (x:xs), is a 

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:

[(_,out)] - error (неопределено)
[]- 0

and here is the result

Parsing p [2*34/3,2+3,2*(6 / 2),]
[22,5,6,0]

It's ok for me, but i have to make it, not showing anything if there are blanks.
I suggest i had to make some checking in the caller function before
calling the eval funcition.
Also somehow i have to check the syntax of the string and if it is
like =x, the result should be x= previous string

Probably i have to user where for the caller function or some if cases :?




2011/6/27 Daniel Patterson lists.hask...@dbp.mm.st:
 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 should have type p :: [String] - [Int].

 Now the base case is obvious - if you are given an empty list of strings, 
 then you should give back an empty list of results.

 The recursive case is a little more complicated - the idea with simple 
 recursion is that the recursive case should eventually land you at the base 
 case, which will stop the recursion. With lists, this usually means that each 
 application of the recursive case should call itself on the rest of the list, 
 and somehow process the first element of the list (it doesnt have to be this 
 way, but often is).

 So in your case, the recursive case should be: evaluate the first element of 
 the list, and then call the whole function on the rest of the list. You can 
 check this mentally by using a couple examples. In the case of a one element 
 list, this means that it will evaluate the first (and only) element of the 
 list, and then call itself on the rest of the list, which is an empty list, 
 which is the bottom case and therefore ends the recursion. On a two element 
 list, this can be checked as well.

 Now the types should be your best friend. You know that you want:

 p :: [String] - [Int]

 That is from the problem statement.

 So you write the base case first:

 p [] = []

 Now for the recursive case, you know you want to eval the first element, and 
 then call the function on the rest of the list. But since you need to return 
 a list eventually, then you need to return a list in this function. You know 
 that calling the function recursively will result in a list (the type 
 guarantees that), so if you've evaluated the first element of a list, 
 resulting in an Int, and you have a list of Int's that is the rest of the 
 list, how do you combine those? Well, put the element at the beginning of the 
 list!

 p (x:xs) = (eval p) : (p xs)


 Now this is a really really common pattern - do the same thing to every 
 element of a list. The first thing in haskell to do if you think that what 
 you are doing might already exist in some generalized form is to try to 
 describe what the function is that you want. So in our case, you want a 
 function that takes another function and applies it to every element in the 
 list. This function would have type:

 (a - b) - [a] - [b]

 In your case the (a - b) is String - Int (the function eval), the [a] is 
 [String], [b] is [Int]. Now if you take this and search on Hoogle (a haskell 
 search engine: 
 http://haskell.org/hoogle/?hoogle=%28a+-%3E+b%29+-%3E+%5Ba%5D+-%3E+%5Bb%5D ), 
 the first result is a function called map, which does exactly what you want. 
 So you can actually write your whole p function as:

 p :: [String] - [Int]
 p xs = map eval xs

 Or, if you are okay with partial application, this is equivalent to:
 p :: [String] - [Int]
 p = map eval

 On Jun 25, 2011, at 3:56 PM, Jack Henahan wrote:

 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 
 sure if that's the effect you're after.

 http://hpaste.org/48324
 Edited code (really just indentation changes and the change from p [] = [] 
 to p [] = 0)

 On Jun 25, 2011, at 3:19 PM, Stoyan Peev wrote:

 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 still breaking down somewhere ...



 2011/6/25 Daniel Patterson lists.hask...@dbp.mm.st:
 what haskell compiler are 

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 type [String] - 
[Maybe Int] - which means that either the calculator has a response (Just 22 or 
Just 6 or Just whatever) or something went wrong (invalid input) and it gave 
Nothing. 

So in your case, you'd get:
 Parsing p [2*34/3,2+3,2*(6 / 2),]
 [Just 22,Just 5,Just 6,Nothing]


Which really clearly demonstrates what you are trying to communicate (and 
importantly doesn't cause the whole program to stop running when it sees a bad 
input). 

Then in the eval function, the error cases would result in Nothing, and the 
good cases would result in Just n. 

On Jun 27, 2011, at 12:09 PM, Stoyan Peev wrote:

 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:
 
[(_,out)] - error (неопределено)
[]- 0
 
 and here is the result
 
 Parsing p [2*34/3,2+3,2*(6 / 2),]
 [22,5,6,0]
 
 It's ok for me, but i have to make it, not showing anything if there are 
 blanks.
 I suggest i had to make some checking in the caller function before
 calling the eval funcition.
 Also somehow i have to check the syntax of the string and if it is
 like =x, the result should be x= previous string
 
 Probably i have to user where for the caller function or some if cases :?
 
 
 
 
 2011/6/27 Daniel Patterson lists.hask...@dbp.mm.st:
 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 should have type p :: [String] - [Int].
 
 Now the base case is obvious - if you are given an empty list of strings, 
 then you should give back an empty list of results.
 
 The recursive case is a little more complicated - the idea with simple 
 recursion is that the recursive case should eventually land you at the base 
 case, which will stop the recursion. With lists, this usually means that 
 each application of the recursive case should call itself on the rest of the 
 list, and somehow process the first element of the list (it doesnt have to 
 be this way, but often is).
 
 So in your case, the recursive case should be: evaluate the first element of 
 the list, and then call the whole function on the rest of the list. You can 
 check this mentally by using a couple examples. In the case of a one element 
 list, this means that it will evaluate the first (and only) element of the 
 list, and then call itself on the rest of the list, which is an empty list, 
 which is the bottom case and therefore ends the recursion. On a two element 
 list, this can be checked as well.
 
 Now the types should be your best friend. You know that you want:
 
 p :: [String] - [Int]
 
 That is from the problem statement.
 
 So you write the base case first:
 
 p [] = []
 
 Now for the recursive case, you know you want to eval the first element, and 
 then call the function on the rest of the list. But since you need to return 
 a list eventually, then you need to return a list in this function. You know 
 that calling the function recursively will result in a list (the type 
 guarantees that), so if you've evaluated the first element of a list, 
 resulting in an Int, and you have a list of Int's that is the rest of the 
 list, how do you combine those? Well, put the element at the beginning of 
 the list!
 
 p (x:xs) = (eval p) : (p xs)
 
 
 Now this is a really really common pattern - do the same thing to every 
 element of a list. The first thing in haskell to do if you think that what 
 you are doing might already exist in some generalized form is to try to 
 describe what the function is that you want. So in our case, you want a 
 function that takes another function and applies it to every element in the 
 list. This function would have type:
 
 (a - b) - [a] - [b]
 
 In your case the (a - b) is String - Int (the function eval), the [a] is 
 [String], [b] is [Int]. Now if you take this and search on Hoogle (a haskell 
 search engine: 
 http://haskell.org/hoogle/?hoogle=%28a+-%3E+b%29+-%3E+%5Ba%5D+-%3E+%5Bb%5D 
 ), the first result is a function called map, which does exactly what you 
 want. So you can actually write your whole p function as:
 
 p :: [String] - [Int]
 p xs = map eval xs
 
 Or, if you are okay with partial application, this is equivalent to:
 p :: [String] - [Int]
 p = map eval
 
 On Jun 25, 2011, at 3:56 

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 still breaking down somewhere ...



2011/6/25 Daniel Patterson lists.hask...@dbp.mm.st:
 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 only 
 my guess, based on the assumption that the whitespace is being converted to a 
 syntax with explicit semilcolon line terminations.

 now, looking at the actual code, the type of the parse function is [a] - 
 [a]. This means that you can parse a list of anything into a list of 
 anything, which doesnt make much sense. This should probably be [String] - 
 [String]  (you are parsing a list of strings to a list of strings, yes?). Now 
 the base case of parse (the first case) makes sense, but look at the second 
 case. parse is being given a list of elements (which you have used pattern 
 matching to decompose, but the whole argument, (x:xs), is a list of 
 elements). You are then passing that, unchanged, to eval. This means that 
 eval must take the same type. Does it? how would you apply eval to each 
 element in that list, instead of just applying it to the whole list?

 On Jun 24, 2011, at 4:31 PM, Stoyan Peev wrote:

 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 from the compiler:

 ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;',
 possibly due to bad layout)


 On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson
 lists.hask...@dbp.mm.st wrote:
 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 
 order functions in your class - would any of the common ones (filter, map, 
 foldr) be helpful here? Would any encapsulate what you are trying to do?

  If you include these kinds of things, I think you'll find this community 
 to be very helpful; without that (showing what your thought process is, why 
 it isn't working, what seems confusing about what the haskell compiler is 
 telling you, etc), you are not going to get help here. People here are very 
 friendly and willing to help people learn; this is not a place to come to 
 get an assignment finished :)

 Also, could you put the library you are using (I'm assuming that this is 
 provided by your university) and the code on somewhere like hpaste.org, so 
 that the formatting is not messed up by email, and it is syntax highlighted?

 On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote:

 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 _expression_ - calculate
 this _expression_. The string result becomes part of the list-result.
 If the _expression_ contains a variable which is not assigned value,
 the result is displayed undefined.
 - If the string has the form- Name = value calculated from the last
 _expression_ is assigned to the variable with the corresponding name
 in the list, and in the result list is formed a string with type
 - If there is not a calculated _expression_ to be assigned to form a
 string no value.
 - If the string is non-blank, but there is a species different from
 the above two case, form the string error.
 - If the string is empty, incl. when it contains only spaces, in the
 result there is not form a string.

 Expressions consist of integers without sign variables, operations +
 (Addition), - (subtraction), * (multiplication) and / (divide) and
 parentheses. Where no brackets, the operations are performed from left
 to right, but * and / precede the + and -. Implementation of any
 operation gives integer; in the division rejected the fractional part,
 if any.
 Variables have names of one letter - from the Latin small letter. In
 the beginning, end or between the elements of each row can have spaces
 - they are irrelevant to its correctness.
 Example: the list-argument
 [3 +7 / 2 2 + x, = s, 2 * s +4, , 2 + +4 / 5]
 function should provide a result-list
 [6, undefined, s = 6, 16, error].


 

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 sure 
if that's the effect you're after.

http://hpaste.org/48324
Edited code (really just indentation changes and the change from p [] = [] to p 
[] = 0)

On Jun 25, 2011, at 3:19 PM, Stoyan Peev wrote:

 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 still breaking down somewhere ...
 
 
 
 2011/6/25 Daniel Patterson lists.hask...@dbp.mm.st:
 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 only 
 my guess, based on the assumption that the whitespace is being converted to 
 a syntax with explicit semilcolon line terminations.
 
 now, looking at the actual code, the type of the parse function is [a] - 
 [a]. This means that you can parse a list of anything into a list of 
 anything, which doesnt make much sense. This should probably be [String] - 
 [String]  (you are parsing a list of strings to a list of strings, yes?). 
 Now the base case of parse (the first case) makes sense, but look at the 
 second case. parse is being given a list of elements (which you have used 
 pattern matching to decompose, but the whole argument, (x:xs), is a list of 
 elements). You are then passing that, unchanged, to eval. This means that 
 eval must take the same type. Does it? how would you apply eval to each 
 element in that list, instead of just applying it to the whole list?
 
 On Jun 24, 2011, at 4:31 PM, Stoyan Peev wrote:
 
 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 from the compiler:
 
 ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;',
 possibly due to bad layout)
 
 
 On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson
 lists.hask...@dbp.mm.st wrote:
 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 
 order functions in your class - would any of the common ones (filter, map, 
 foldr) be helpful here? Would any encapsulate what you are trying to do?
 
  If you include these kinds of things, I think you'll find this community 
 to be very helpful; without that (showing what your thought process is, 
 why it isn't working, what seems confusing about what the haskell compiler 
 is telling you, etc), you are not going to get help here. People here are 
 very friendly and willing to help people learn; this is not a place to 
 come to get an assignment finished :)
 
 Also, could you put the library you are using (I'm assuming that this is 
 provided by your university) and the code on somewhere like hpaste.org, so 
 that the formatting is not messed up by email, and it is syntax 
 highlighted?
 
 On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote:
 
 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 _expression_ - calculate
 this _expression_. The string result becomes part of the list-result.
 If the _expression_ contains a variable which is not assigned value,
 the result is displayed undefined.
 - If the string has the form- Name = value calculated from the last
 _expression_ is assigned to the variable with the corresponding name
 in the list, and in the result list is formed a string with type
 - If there is not a calculated _expression_ to be assigned to form a
 string no value.
 - If the string is non-blank, but there is a species different from
 the above two case, form the string error.
 - If the string is empty, incl. when it contains only spaces, in the
 result there is not form a string.
 
 Expressions consist of integers without sign variables, operations +
 (Addition), - (subtraction), * (multiplication) and / (divide) and
 

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 order functions in 
your class - would any of the common ones (filter, map, foldr) be helpful here? 
Would any encapsulate what you are trying to do?

 If you include these kinds of things, I think you'll find this community to be 
very helpful; without that (showing what your thought process is, why it isn't 
working, what seems confusing about what the haskell compiler is telling you, 
etc), you are not going to get help here. People here are very friendly and 
willing to help people learn; this is not a place to come to get an assignment 
finished :)

Also, could you put the library you are using (I'm assuming that this is 
provided by your university) and the code on somewhere like hpaste.org, so that 
the formatting is not messed up by email, and it is syntax highlighted?

On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote:

 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 _expression_ - calculate
 this _expression_. The string result becomes part of the list-result.
 If the _expression_ contains a variable which is not assigned value,
 the result is displayed undefined.
 - If the string has the form- Name = value calculated from the last
 _expression_ is assigned to the variable with the corresponding name
 in the list, and in the result list is formed a string with type
 - If there is not a calculated _expression_ to be assigned to form a
 string no value.
 - If the string is non-blank, but there is a species different from
 the above two case, form the string error.
 - If the string is empty, incl. when it contains only spaces, in the
 result there is not form a string.
 
 Expressions consist of integers without sign variables, operations +
 (Addition), - (subtraction), * (multiplication) and / (divide) and
 parentheses. Where no brackets, the operations are performed from left
 to right, but * and / precede the + and -. Implementation of any
 operation gives integer; in the division rejected the fractional part,
 if any.
 Variables have names of one letter - from the Latin small letter. In
 the beginning, end or between the elements of each row can have spaces
 - they are irrelevant to its correctness.
 Example: the list-argument
 [3 +7 / 2 2 + x, = s, 2 * s +4, , 2 + +4 / 5]
 function should provide a result-list
 [6, undefined, s = 6, 16, error].
 
 
 I say another person have the same task, but he didn't do anything. I
 started doing this task myself but i get stuck in the middle. Then i
 started searching for something that could help me and find out you :)
 
 The code i have written so far uses the library file Parsing.lhs
 but what i have written is taking those actions that i already
 described, only for a string. I cannot modify it to work for list of
 string, and complete the whole task.
 
 I'll be glad to finish the task myself, but i am going to need some help.
 
 Here is the code i have already written:
 
 
 import Parsing
 
 expr  :: Parser Int
 expr  =  do t - term
do symbol +
   e - expr
   return (t+e)
  +++ do symbol -
 e - expr
 return (t-e)
  +++ return t
 term  :: Parser Int
 term  =  do f - factor
do symbol *
   t - term
   return (f * t)
  +++ do symbol /
 t - term
 return (f-t)
  +++ return f
 factor:: Parser Int
 factor=  do symbol (
e - expr
symbol )
return e
  +++ natural
 eval  :: String - Int
 eval xs   =  case (parse expr xs) of
[(n,[])]  - n
[(_,out)] - error (undefined)
[]- error error
 
 
 
 Thanks all in advance :)
 
 --
 Best Wishes
 Stoyan Peev
 
 

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 from the compiler:

ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;',
possibly due to bad layout)


On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson
lists.hask...@dbp.mm.st wrote:
 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 order 
 functions in your class - would any of the common ones (filter, map, foldr) 
 be helpful here? Would any encapsulate what you are trying to do?

  If you include these kinds of things, I think you'll find this community to 
 be very helpful; without that (showing what your thought process is, why it 
 isn't working, what seems confusing about what the haskell compiler is 
 telling you, etc), you are not going to get help here. People here are very 
 friendly and willing to help people learn; this is not a place to come to get 
 an assignment finished :)

 Also, could you put the library you are using (I'm assuming that this is 
 provided by your university) and the code on somewhere like hpaste.org, so 
 that the formatting is not messed up by email, and it is syntax highlighted?

 On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote:

 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 _expression_ - calculate
 this _expression_. The string result becomes part of the list-result.
 If the _expression_ contains a variable which is not assigned value,
 the result is displayed undefined.
 - If the string has the form- Name = value calculated from the last
 _expression_ is assigned to the variable with the corresponding name
 in the list, and in the result list is formed a string with type
 - If there is not a calculated _expression_ to be assigned to form a
 string no value.
 - If the string is non-blank, but there is a species different from
 the above two case, form the string error.
 - If the string is empty, incl. when it contains only spaces, in the
 result there is not form a string.

 Expressions consist of integers without sign variables, operations +
 (Addition), - (subtraction), * (multiplication) and / (divide) and
 parentheses. Where no brackets, the operations are performed from left
 to right, but * and / precede the + and -. Implementation of any
 operation gives integer; in the division rejected the fractional part,
 if any.
 Variables have names of one letter - from the Latin small letter. In
 the beginning, end or between the elements of each row can have spaces
 - they are irrelevant to its correctness.
 Example: the list-argument
 [3 +7 / 2 2 + x, = s, 2 * s +4, , 2 + +4 / 5]
 function should provide a result-list
 [6, undefined, s = 6, 16, error].


 I say another person have the same task, but he didn't do anything. I
 started doing this task myself but i get stuck in the middle. Then i
 started searching for something that could help me and find out you :)

 The code i have written so far uses the library file Parsing.lhs
 but what i have written is taking those actions that i already
 described, only for a string. I cannot modify it to work for list of
 string, and complete the whole task.

 I'll be glad to finish the task myself, but i am going to need some help.

 Here is the code i have already written:


 import Parsing

 expr                          :: Parser Int
 expr                          =  do t - term
                                    do symbol +
                                       e - expr
                                       return (t+e)
                                      +++ do symbol -
                                             e - expr
                                             return (t-e)
                                      +++ return t
 term                          :: Parser Int
 term                          =  do f - factor
                                    do symbol *
                                       t - term
                                       return (f * t)
                                      +++ do symbol /
                                             t - term
                                             return (f-t)
                                      +++ return f
 factor                        :: Parser Int
 factor                        =  do symbol (
                                    e 

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 only my 
guess, based on the assumption that the whitespace is being converted to a 
syntax with explicit semilcolon line terminations. 

now, looking at the actual code, the type of the parse function is [a] - [a]. 
This means that you can parse a list of anything into a list of anything, which 
doesnt make much sense. This should probably be [String] - [String]  (you are 
parsing a list of strings to a list of strings, yes?). Now the base case of 
parse (the first case) makes sense, but look at the second case. parse is being 
given a list of elements (which you have used pattern matching to decompose, 
but the whole argument, (x:xs), is a list of elements). You are then passing 
that, unchanged, to eval. This means that eval must take the same type. Does 
it? how would you apply eval to each element in that list, instead of just 
applying it to the whole list? 

On Jun 24, 2011, at 4:31 PM, Stoyan Peev wrote:

 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 from the compiler:
 
 ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;',
 possibly due to bad layout)
 
 
 On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson
 lists.hask...@dbp.mm.st wrote:
 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 
 order functions in your class - would any of the common ones (filter, map, 
 foldr) be helpful here? Would any encapsulate what you are trying to do?
 
  If you include these kinds of things, I think you'll find this community to 
 be very helpful; without that (showing what your thought process is, why it 
 isn't working, what seems confusing about what the haskell compiler is 
 telling you, etc), you are not going to get help here. People here are very 
 friendly and willing to help people learn; this is not a place to come to 
 get an assignment finished :)
 
 Also, could you put the library you are using (I'm assuming that this is 
 provided by your university) and the code on somewhere like hpaste.org, so 
 that the formatting is not messed up by email, and it is syntax highlighted?
 
 On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote:
 
 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 _expression_ - calculate
 this _expression_. The string result becomes part of the list-result.
 If the _expression_ contains a variable which is not assigned value,
 the result is displayed undefined.
 - If the string has the form- Name = value calculated from the last
 _expression_ is assigned to the variable with the corresponding name
 in the list, and in the result list is formed a string with type
 - If there is not a calculated _expression_ to be assigned to form a
 string no value.
 - If the string is non-blank, but there is a species different from
 the above two case, form the string error.
 - If the string is empty, incl. when it contains only spaces, in the
 result there is not form a string.
 
 Expressions consist of integers without sign variables, operations +
 (Addition), - (subtraction), * (multiplication) and / (divide) and
 parentheses. Where no brackets, the operations are performed from left
 to right, but * and / precede the + and -. Implementation of any
 operation gives integer; in the division rejected the fractional part,
 if any.
 Variables have names of one letter - from the Latin small letter. In
 the beginning, end or between the elements of each row can have spaces
 - they are irrelevant to its correctness.
 Example: the list-argument
 [3 +7 / 2 2 + x, = s, 2 * s +4, , 2 + +4 / 5]
 function should provide a result-list
 [6, undefined, s = 6, 16, error].
 
 
 I say another person have the same task, but he didn't do anything. I
 started doing this task myself but i get stuck in the middle. Then i
 started searching for something that could help me and find out you :)
 
 The code i have written so far uses the library file Parsing.lhs
 but what i have written is taking those actions that i already
 described, only for a string. 

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 objects.
 -- Solution: implement our own dynamics...
 --
 -- The problem with dynload is that it requires the plugin to export
 -- a value that is a Dynamic (in our case a (TypeRep,a) pair). If this
 -- is not the case, we core dump. Use pdynload if you don't trust the
 -- user to supply you with a Dynamic
 \end{comment}

Thanks, after playing with that I've got something working.  Though
I'd still need to dynamically link this thing, because the default
behavior is to take 30 seconds to compile and link a 58 MB executable.
 Not good during development.

I've reported a bug for the runhaskell case [1], since it gives me a
message about strange closure type 894 and says Please report this
as a GHC bug.

Rob

[1] http://hackage.haskell.org/trac/ghc/ticket/5053

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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.

 http://stackoverflow.com/questions/542/help-with-haskell-dynamic-plugin-load

Hi Rob,

I don't have a stack overflow account, so I will give a partial answer here.

I'm not sure what the issue is with runhaskell, but you are getting a
segfault with dynload. The comments on dynload in the source of the
plugins package reveal the probable cause:

\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 objects.
-- Solution: implement our own dynamics...
--
-- The problem with dynload is that it requires the plugin to export
-- a value that is a Dynamic (in our case a (TypeRep,a) pair). If this
-- is not the case, we core dump. Use pdynload if you don't trust the
-- user to supply you with a Dynamic
\end{comment}

So it seems that, to use dynload, you must export a pair containing a
typerep and a value, rather than just a value. Plugins also provides
pdynload, which is apparently a super-replacement for dynload,
though I didn't look into it in detail.

Cheers,
Bernie.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 make sure that your assessments of the
 performance difference are grounded in statistically robust reasoning :)
  Progression may also help.

Thanks. These look useful.

 GHC 7 has a new rts option, +RTS -H -RTS that gives you a good high default
 for these memory numbers.  You might give it ago, but I doubt it's going to
 help much here.

It didn't seem to, no.

 One thing I noticed was that you calculate the length of elts more than once
 inside aggregate.  It's probably not going to account for a big boost, but
 I'd recommend doing it only once.  Something like:
   let lenelts = length elts
 Then use lenelts everywhere.

This doesn't seem to make much difference - elts is only a thousand or
so items.

 Also, it seems like you use Data.Set to sort and uniquify the input then you
 throw away the Set, that's potentially costly.

This is actually the fastest way I've found to do it! It replaced an
earlier implementation that looked like it should have been more
optimised but wasn't. If you have any better suggestions, I'm
definitely open to hearing them.

 There are probably better
 types for aggregate than [[a]] - [a].

What did you have in mind? That's largely the format the data comes in
as, so other than changing from lists to some other ordered container
I'm not sure what to change.

 You use Arrays, but it's possible
 that a different vector library such as Data.Vector gives better performance
 here.

For the case I'm using arrays I'm specifically using unboxed double
arrays with integer indices, mainly because I do a very large number
of lookups.

 Or, perhaps you want that instead of lists everywhere.

Possibly. I looked into it briefly and it's not that easy to do. In
particular there are important bits in the code which depend on being
able to do pull the list apart head/tail-wise. It might be possible
for some of this to use vectors internally, or I might be able to
replace those with something else. I'm not entirely sure.

 For example,
 you build an index and a reverse index.  It seems like with an array or
 vector you could eliminate at least one index and have O(1) lookup time
 instead of Data.Map's O(log n) lookup time.

Yeah, in particular the reverse index really should be a vector. But
that particular code is only actually used once right at the end and
takes a tiny amount of time, so it's not actually that useful to do so
I think.

 I hope that helps,

It does. Thanks!

David

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 That
 thing that Hammer Principle does).

 Two questions immediately begs themselves:

 * Can we go parallel? :P

Maybe. A lot of this is inherently sequential. Some bits are
parallelisable, but my initial attempts at exploiting that made very
little performance difference. I'd rather exhaust what I can from
single-core performance first.

 * What does +RTS -s -RTS say? Specifically, what is the current
 productivity?

./rank +RTS -s
   3,466,696,368 bytes allocated in the heap
 212,888,240 bytes copied during GC
  51,949,568 bytes maximum residency (10 sample(s))
   5,477,016 bytes maximum slop
 105 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:  6546 collections, 0 parallel,  0.93s,  0.93s elapsed
  Generation 1:10 collections, 0 parallel,  0.32s,  0.32s elapsed

  INIT  time0.00s  (  0.00s elapsed)
  MUT   time7.11s  (  7.12s elapsed)
  GCtime1.25s  (  1.25s elapsed)
  EXIT  time0.00s  (  0.00s elapsed)
  Total time8.37s  (  8.37s elapsed)

  %GC time  15.0%  (15.0% elapsed)

  Alloc rate487,319,292 bytes per MUT second

  Productivity  85.0% of total user, 85.0% of total elapsed

So if I'm reading this right, my hypothesis that allocation was most
of the cost seems to be wrong? I don't know how much of that MUT time
is allocation, but I'd expect it to be  GC time.

 Do we get an improvement with +RTS -A2m -H128m -RTS ?
 (Force the heap to be somewhat up there from day one, perhaps try
 -H256m.

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.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 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:
 
  * Can we go parallel? :P

 Maybe. A lot of this is inherently sequential. Some bits are
 parallelisable, but my initial attempts at exploiting that made very
 little performance difference. I'd rather exhaust what I can from
 single-core performance first.

  * What does +RTS -s -RTS say? Specifically, what is the current
  productivity?

 ./rank +RTS -s
   3,466,696,368 bytes allocated in the heap
 212,888,240 bytes copied during GC
  51,949,568 bytes maximum residency (10 sample(s))
   5,477,016 bytes maximum slop
 105 MB total memory in use (0 MB lost due to fragmentation)

  Generation 0:  6546 collections, 0 parallel,  0.93s,  0.93s elapsed
  Generation 1:10 collections, 0 parallel,  0.32s,  0.32s elapsed

  INIT  time0.00s  (  0.00s elapsed)
  MUT   time7.11s  (  7.12s elapsed)
  GCtime1.25s  (  1.25s elapsed)
  EXIT  time0.00s  (  0.00s elapsed)
  Total time8.37s  (  8.37s elapsed)

  %GC time  15.0%  (15.0% elapsed)

  Alloc rate487,319,292 bytes per MUT second

  Productivity  85.0% of total user, 85.0% of total elapsed

 So if I'm reading this right, my hypothesis that allocation was most
 of the cost seems to be wrong? I don't know how much of that MUT time
 is allocation, but I'd expect it to be  GC time.

  Do we get an improvement with +RTS -A2m -H128m -RTS ?
  (Force the heap to be somewhat up there from day one, perhaps try
  -H256m.

 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 make sure that your assessments of the
performance difference are grounded in statistically robust reasoning :)
 Progression may also help.

GHC 7 has a new rts option, +RTS -H -RTS that gives you a good high default
for these memory numbers.  You might give it ago, but I doubt it's going to
help much here.

One thing I noticed was that you calculate the length of elts more than once
inside aggregate.  It's probably not going to account for a big boost, but
I'd recommend doing it only once.  Something like:
  let lenelts = length elts

Then use lenelts everywhere.

Also, it seems like you use Data.Set to sort and uniquify the input then you
throw away the Set, that's potentially costly.  There are probably better
types for aggregate than [[a]] - [a].  You use Arrays, but it's possible
that a different vector library such as Data.Vector gives better performance
here.  Or, perhaps you want that instead of lists everywhere.  For example,
you build an index and a reverse index.  It seems like with an array or
vector you could eliminate at least one index and have O(1) lookup time
instead of Data.Map's O(log n) lookup time.

I hope that helps,
Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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:

* Can we go parallel? :P
* What does +RTS -s -RTS say? Specifically, what is the current
productivity? Do we get an improvement with +RTS -A2m -H128m -RTS ?
(Force the heap to be somewhat up there from day one, perhaps try
-H256m.

-- 
J.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 adding
 function (:) doesn´t work on my own data types.
 This is my code:
 data Allele = Aone | Atwo
    deriving Show
 type Lifespan = Int
 data Population = Pop [(Allele,Allele,Lifespan)]
    deriving Show


I don't know what precise behavior you want to model, but can you use
the '++' operator in your definition?

 (Pop x) +- (Pop y) = Pop (x ++ y)

Antoine

 genepool :: Population
 genepool = Pop []

 --can only concatenate 2 elements
 (+-) :: Population - Population - Population
 Pop [(a,b,c)] +- Pop [] = Pop [(a,b,c)]
 Pop [(a,b,c)] +- Pop [(d,e,f)] = Pop [(a,b,c),(d,e,f)]

 --and thats why this function goes non-exhaustive.
 gpinsertaoneaone :: Int - Int - Population
 gpinsertaoneaone 0 age = genepool
 gpinsertaoneaone n age = Pop [(Aone,Aone,70-age)] +- gpinsertaoneaone (n-1)
 age

 Thx for help and advice!


 --
 View this message in context: 
 http://haskell.1045720.n5.nabble.com/Help-with-how-to-concatenate-with-own-datatypes-tp3424433p3424433.html
 Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.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] 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 to only execute once.  It's most useful when working with some
sort of lazy data structure like a list, tree, or graph.

I can't come up with an example for IO off the top of my head, but for the
ICFP contest this year I wrote a gate/wire embedded language which had code
that looks like this:

sample wireIn = do
   rec
   (wireOut,a) - gate (wireIn,d)
   (d,b) - gate (a, b)
   return wireOut

which would create a circuit like this:

---in-[  ]--out
  +-d-[  ]--a--[  ]-d---+
  | +-b-[  ]-b-+ |
  | +---+ |
  +---+

This code translates to something like

sample wireIn = do
(wireOut, _, _, _) - mfix $ \(_, b, d) - do
(wireOut', a) - gate (wireIn, d)
(d', b') - gate (a,b)
return (wireOut', b', d')
return wireOut'

The key is that gate was lazy in its arguments; the gate didn't care what
its input wires were, it just needed them to exist at the time you asked for
the entire circuit definition.  mfix says 'run the *effects* in this code
once, but the *data* might be recursive'.

  -- ryan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 ()

How can I implement the 'toByteString' function?


Why do you want to convert? If you process images you might consider one 
of the Vector libraries like storable-vector or vector. You can work on 
them in a mutable way, write them to disk, pass them to C libraries and so 
on.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 freeze to convert your IOArray into an IArray
* Use putIArrayOf and put (from cereal) to generate a Putter value
* Use runPut to generate a ByteString from that

Michael

On Tue, Feb 8, 2011 at 10:49 AM, C K Kashyap ckkash...@gmail.com wrote:
 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' function?
 Regards,
 Kashyap
 ___
 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] 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 you know if you need big or little endian?

 A basic approach would be:

 * Use freeze to convert your IOArray into an IArray
 * Use putIArrayOf and put (from cereal) to generate a Putter value
 * Use runPut to generate a ByteString from that


Thanks Michael,
Actually, I need an array of 8-bit words - Is that available?

Also, would be hard to do it without cereal?

Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 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 freeze to convert your IOArray into an IArray
 * Use putIArrayOf and put (from cereal) to generate a Putter value
 * Use runPut to generate a ByteString from that


 Thanks Michael,
 Actually, I need an array of 8-bit words - Is that available?
 Also, would be hard to do it without cereal?
 Regards,
 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

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 the getImageByteString
function at https://github.com/ckkashyap/Chitra/blob/master/RFB/Encoding.hs
Looks like this is pretty slow, and hence I am exploring Arrays.

I wonder if working with [Word8] will also suffer from performance hit?

Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 wonder if working with [Word8] will also suffer from performance hit?

If the only thing you use [Word8] for is converting between arrays (for
image processing) and bytestrings (for IO), it is an O(n) cost added to
an already O(n) operation, so it's probably liveable.  

The intermediate list might be optimized away, and in any case, your
program might still be limited by disk bandwidth, so if you're lucky,
it boils down to a matter of using 20% or 40% CPU when doing file IO.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 tuples - [(Int,Int,Int)] to represent an
 image buffer. You can see it in the getImageByteString
 function at https://github.com/ckkashyap/Chitra/blob/master/RFB/Encoding.hs
 Looks like this is pretty slow, and hence I am exploring Arrays.
 I wonder if working with [Word8] will also suffer from performance hit?
 Regards,
 Kashyap

Using Data.ByteString.Internal.create along with readArray to fill in
the contents seems like it would be a fast option (though I haven't
tried it).

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe





-- 
Work is punishment for failing to procrastinate effectively.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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?

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 transformers package, but MonadRandom uses mtl.

 =
 MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0
/doc/html/Control-Monad-IO-Class.html#t:MonadIO


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 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?




-- 
JP Moresmau
http://jpmoresmau.blogspot.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 
MonadIO used by MonadRandom is not the same as the one provided by 
transformers. Reinstall mtl to get version 2.* and MonadRandom if that's 
the case.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 
daniel.is.fisc...@googlemail.com wrote:

 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
 MonadIO used by MonadRandom is not the same as the one provided by
 transformers. Reinstall mtl to get version 2.* and MonadRandom if that's
 the case.




-- 
JP Moresmau
http://jpmoresmau.blogspot.com/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
 does compile because of the special symbols I wish to use. So presumably
 I need to pre-process my file before submitting to ghci. However, I was
 unable to find any information about this in the excellent guide. For
 example:
 
  \documentclass{beamer}
 
  %include polycode.fmt
  %format m_ = \mu
  %format ^ =  
  %format inv(a) = a^^\circ
  %format in_ = in
 
  \begin{document}
 
  \title{Some Notes on Category Theory with Some Applications to Computer
Science}
 
  \author{Dominic Steinitz}
 
  \begin{frame}
\frametitle{Haskell Example: Total}
  Initial algebras can be defined as follows:
  \begin{code}
  newtype m_^f = In {inv(in_) :: f (m_^f )}
  \end{code}
  \end{frame}
 
 
  \end{document}
 produces a nice slide but does not compile.
 
 If I change the offending line to
 
  newtype Mu f = In {in_ :: f (Mu f)}
 then all is well but the slide does not look as nice

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
 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 all things once they are
explained). Many thanks, Dominic.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 Data.Dynamic.

 Then your monad is just StateT Dynamic, where your magical maybeifying get is:

 getD :: (Monad m, Typeable a) = StateT Dynamic m a
 getD = maybe (fail Type error) return . cast = get

 Luke


Thanks a lot, Luke. I'd never run across Data.Dynamic before, but
figured something like this existed. Looks perfect.

Thanks so much,
Brandon


 On Mon, Dec 6, 2010 at 9:09 PM, Brandon Simmons
 brandon.m.simm...@gmail.com wrote:
 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
 that the state types must always be of the Typeable class (see:
 http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Typeable.html
 ).

 The idea is that the new monad would be something like 'StateT s Maybe
 a', but where the 's' type is not fixed (indeed is hidden in an
 existential type) and where any programmer errors in the chaining of
 the polymorphic state will be caught in the Maybe type (or really the
 'fail' implementation of any monad).

 Here is how I imagine a computation might look:

    computation :: TypeableState Maybe String
    computation = do
        (c:cs) -  getTS
        putTS (length cs)
        return (c ++  was the first letter of the string passed as
 initial state.)

 So TypeableState is very similar to StateT, except that the state type
 is not present as a type argument. In the example above 'Maybe' is the
 monad that catches Typeable errors, and String is the return type of
 the computation.

 getTS and putTS would be get and put functions that constrain their
 arguments to the Typeable class.

 Here is what I have so far (at least this is my most recent
 uncommented attempt):

 {-# LANGUAGE ExistentialQuantification #-}
 module Main
       where

 import Control.Monad.State
 import Data.Typeable

 -- we might have restricted our 'm' to MonadPlus and used the explicit
 -- 'mzero', but decided instead to use Monad, with 'fail'. This is
 -- more appropriate since we won't be using 'mplus'. See 'liftMaybe'.
 data TypeableState m a = forall s0 sN. (Typeable s0, Typeable sN)=
                            TypeableState (s0 - m (a,sN))

 -- this is probably one of the more non-sensical attempts I've made at
 -- this... but I'm not sure:
 runTypeableState :: (Monad m, Typeable s0, Typeable sN)= TypeableState m a 
 - s0 - m (a,sN)
 runTypeableState (TypeableState st) s0 = (liftMaybe $ cast s0) = st

 -- copied from Control.Monad.StateT
 instance (Monad m) = Monad (TypeableState m) where
     return a = TypeableState $ \s - return (a, s)
     m = k  = TypeableState $ \s - do
         ~(a, s') - runTypeableState m s
         runTypeableState (k a) s'
     fail str = TypeableState $ \_ - fail str

 -- I imagine using this with 'cast' to thread the type in our monad
 -- transformer
 liftMaybe :: (Monad m)= Maybe a - m a
 liftMaybe = maybe (fail Monadic failure) return

 So is this even feasible? Or do I not grok what we can and can't do
 with the Typeable class?

 Any thoughts on this are appreciated.

 Sincerely,
 Brandon Simmons
 http://coder.bsimmons.name

 ___
 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] 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 maybeifying get is:

getD :: (Monad m, Typeable a) = StateT Dynamic m a
getD = maybe (fail Type error) return . cast = get

Luke

On Mon, Dec 6, 2010 at 9:09 PM, Brandon Simmons
brandon.m.simm...@gmail.com wrote:
 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
 that the state types must always be of the Typeable class (see:
 http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Typeable.html
 ).

 The idea is that the new monad would be something like 'StateT s Maybe
 a', but where the 's' type is not fixed (indeed is hidden in an
 existential type) and where any programmer errors in the chaining of
 the polymorphic state will be caught in the Maybe type (or really the
 'fail' implementation of any monad).

 Here is how I imagine a computation might look:

    computation :: TypeableState Maybe String
    computation = do
        (c:cs) -  getTS
        putTS (length cs)
        return (c ++  was the first letter of the string passed as
 initial state.)

 So TypeableState is very similar to StateT, except that the state type
 is not present as a type argument. In the example above 'Maybe' is the
 monad that catches Typeable errors, and String is the return type of
 the computation.

 getTS and putTS would be get and put functions that constrain their
 arguments to the Typeable class.

 Here is what I have so far (at least this is my most recent
 uncommented attempt):

 {-# LANGUAGE ExistentialQuantification #-}
 module Main
       where

 import Control.Monad.State
 import Data.Typeable

 -- we might have restricted our 'm' to MonadPlus and used the explicit
 -- 'mzero', but decided instead to use Monad, with 'fail'. This is
 -- more appropriate since we won't be using 'mplus'. See 'liftMaybe'.
 data TypeableState m a = forall s0 sN. (Typeable s0, Typeable sN)=
                            TypeableState (s0 - m (a,sN))

 -- this is probably one of the more non-sensical attempts I've made at
 -- this... but I'm not sure:
 runTypeableState :: (Monad m, Typeable s0, Typeable sN)= TypeableState m a 
 - s0 - m (a,sN)
 runTypeableState (TypeableState st) s0 = (liftMaybe $ cast s0) = st

 -- copied from Control.Monad.StateT
 instance (Monad m) = Monad (TypeableState m) where
     return a = TypeableState $ \s - return (a, s)
     m = k  = TypeableState $ \s - do
         ~(a, s') - runTypeableState m s
         runTypeableState (k a) s'
     fail str = TypeableState $ \_ - fail str

 -- I imagine using this with 'cast' to thread the type in our monad
 -- transformer
 liftMaybe :: (Monad m)= Maybe a - m a
 liftMaybe = maybe (fail Monadic failure) return

 So is this even feasible? Or do I not grok what we can and can't do
 with the Typeable class?

 Any thoughts on this are appreciated.

 Sincerely,
 Brandon Simmons
 http://coder.bsimmons.name

 ___
 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] 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, CharT)]

 will return:

  (string, 001, 'c')

 So how to use TH write 'parse' function?

I think that you should use TH properly, without compiler and logical errors.

What actually do you want?

I think that parse should have type (parse :: [(String, DataType)] - Q Exp).

I think that OverloadedStrings extension should serve you as well.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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:

  parse [(string, StringT), (001, IntT), (c, CharT)]

 will return:

  (string, 001, 'c')

 So how to use TH write 'parse' function?

 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.

Example i have two processes : Client and Server.

At Client side, i pass [DataType] to Server, example:

  [StringT, IntT, CharT]

Server will handle user input with [DataType] 
and return result [String] to Client side, example:

  [string, 001, c]

Then at Client side, i need parse [String] to get real value:

  (string, 001, 'c')
  
Because, [DataType] have many different case, so i want pass [String]
between processes, and use TH parse result [String] at Client side.

Thanks,

  -- Andy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 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:
 
   parse [(string, StringT), (001, IntT), (c, CharT)]
 
  will return:
 
   (string, 001, 'c')
 
  So how to use TH write 'parse' function?
 
  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.

 Example i have two processes : Client and Server.

 At Client side, i pass [DataType] to Server, example:

  [StringT, IntT, CharT]

 Server will handle user input with [DataType]
 and return result [String] to Client side, example:

  [string, 001, c]

 Then at Client side, i need parse [String] to get real value:

  (string, 001, 'c')

 Because, [DataType] have many different case, so i want pass [String]
 between processes, and use TH parse result [String] at Client side.

 Thanks,

  -- Andy
 ___
 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] 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 write a class Ask:

class Ask a where ask :: YourMonad a

and then instance it:

instance Ask Int where ask = liftIO $ do { putStrLn Enter integer:;
l - getLine; return $ read l}
instance Ask Char where ask = liftIO $ do { putStrLn Enter char:; l
- getLine; return $ head l}
instance Ask String where ask = liftIO $ do { putStrLn Enter
string:; l - getLine; return l}
instance (Ask a, Ask b, Ask c) = Ask (a,b,c) where ask = liftIO $ do
{ a - ask; b - ask; c - ask; return (a,b,c)}

You can pass ask values between processes, receiving results of asking.

TH is great and good, but it is that only when you absolutely
exhausted of usual Haskell options.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 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 the showPic,
 sizeRaw and isPic.
 questions are:
 1)  – Define showPic :: Canvas - IO () for displaying pictures on the
 terminal. Examples:
 Cw2010 showPic (painting 2)
 +---+---+---+---+---+
 | a | n | e | x | a |
 +---+---+---+---+---+
 | m | p | l | e | t |
 +---+---+---+---+---+
 | e | x | t | i | s |
 +---+---+---+---+---+
 | s | h | o | w | n |
 +---+---+---+---+---+
 Cw2010 showPic (painting 3)
 +---+---+---+---+---+---+---+
 | A | n | o | t | h | e | r |
 +---+---+---+---+---+---+---+
 | | t | e | s | t | ! | |
 +---+---+---+---+---+---+---+
 2)  – Furthermore, define sizeRaw :: Canvas - (Int, Int) for finding
 out the size of a raw picture as demonstrated here.
 Cw2010 sizeRaw [anexa,mplet,extis,shown]
 (5,4)
 3)  – Finally, define isPic :: Canvas - Bool for checking a particular
 necessary condition which items of type Canvas must satisfy (full or
 raw). The condition you should check for is whether all the ‘rows’ of
 the input have the same length. (It may be assumed that the input
 of isPic is of type Canvas.) Examples:
 Cw2010 isPic (painting 3)
 True
 Cw2010 isPic (painting 4)
 False
 Suggestion. I found it useful in my implementation to define and use
 here the auxiliary function isEqual :: [Int] - Bool; example:
 Cw2008 isEqual [8,8,8,8]
 True
 Cw2008 isEqual [8,8,4,8]
 False
 You may wish to define and use isEqual in your implementation of
 isPic too.
 ___
 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] 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 _   _ []  = []

Moving average can be interpreted as convolution (*):
[1/n,1/n,1/n,...,1/n] * xs

You may drop the first (n-1) values, since they average over initial
padding zeros.

Convolution is associative and you can decompose the first operand into
simpler parts:

1/n · [1,1,1,...] * [1,0,0,,0,0,-1] * xs
 = 1/n · integrate ([1,0,0,,0,0,-1] * xs)

Convolution is commutative, thus you could also write
 = 1/n · [1,0,0,,0,0,-1] * integrate xs
 but then integration of xs will yield unbounded values and thus higher
rounding errors.

This yields:

movingAverage :: Int - [Float] - [Float]
movingAverage n =
   drop (n-1) .
   map (/ fromIntegral n) .
   scanl1 (+) .
   (\xs - zipWith (-) xs (replicate n 0 ++ xs))

This should be the same as the implementation above, but maybe a bit
nicer. :-)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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
   runSums _   _ []  = []
 
 Doaitse
 
 I very very carefully avoided doing any such thing in my example code.
 For each output result, my code does two additions and one division.
 Yours does one addition, one subtraction, and one division, for the
 required case n = 3.  The way I formulated it, each calculation is
 independent.  The way you've formulated it, the error in one
 calculation accumulates into the next.  NOT a good idea.

If this an issue then:

module MovingAverage where

movingAverage :: [Float] - [Float]
movingAverage (x:y:l) = movingAverage' x y l
where movingAverage' x y (z:zs) = (x+y+z)/3:movingAverage' y z zs
  movingAverage' _ _ _  = []
movingAverage _   = []


has far fewer pattern matches,

 Doaitse


 
 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 sep 2010, at 03:40, Richard O'Keefe wrote:

 
 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?
 
 [(1,0),(2,0),(3,2),(4,3)] :: [(Double,Double)]
 
 moving_average3 (xs0 @ (_ : (xs1 @ (_ : xs2 =
  zipWith3 (\x y z - (x+y+z)/3) xs0 xs1 xs2
 
 *Main moving_average3 [1..10]
 [2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0]
 
 The result is two elements shorter than the original, but that
 _is_ the definition of moving average after all.
 ___
 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] 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?
 
 [(1,0),(2,0),(3,2),(4,3)] :: [(Double,Double)]

 moving_average3 (xs0 @ (_ : (xs1 @ (_ : xs2 =
   zipWith3 (\x y z - (x+y+z)/3) xs0 xs1 xs2

*Main moving_average3 [1..10]
[2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0]

The result is two elements shorter than the original, but that
_is_ the definition of moving average after all.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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?

 [(1,0),(2,0),(3,2),(4,3)] :: [(Double,Double)]

 (1,0) the average is zero as the length is less than 3

 (2,0) the average is zero as the length is less than 3

 (3,2) the average is (1+2+3)/3 = 2

 (4,3) the average is (2+3+4)/3 = 9

movingAverage n xs = map (/n) $ sums n xs

sums 1 xs = xs
sums n xx@(x:xs) = zipWith (+) xx (sums (n-1) xs)

Tests:
*Main movingAverage 1 [1..10]
[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0]
*Main movingAverage 2 [1..10]
[1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5]
*Main movingAverage 3 [1..10]
[2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0]
*Main movingAverage 4 [1..10]
[2.5,3.5,4.5,5.5,6.5,7.5,8.5]

Is it right? ;)

It is more interesting to create movingAverage in CPS/iteratees style.
That way you'll have solid interface with IO world and you can freely
alternate between reading moving averages and waiting for another
ticket. No magic usafeInterleaveIO, hGetContents, etc, will be
required.

I did this once for my friend's pet project in Erlang, we jointly
developed a whole library of operators over time series - sums,
averages, etc. It is simple and fun. ;)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 need to
do for that?


On Sun, Sep 5, 2010 at 11:12 PM, Don Stewart d...@galois.com wrote:
 Gaius:
 My usual rhetoric is that one-off, throwaway scripts never are, and
 not only do they tend to stay around but they take on a life of their
 own. Today's 10-line file munger is tomorrow's thousand-line ETL batch
 job on which the business depends for some crucial data - yet the
 original author is long gone and no-one dares modify in case it
 breaks. So it is just good sense to use sound practices from the very
 beginning.

 I gave a tech talk recently on using Haskell for scripting -- and it is
 built on the idea that today's throw away script is tomorrow's key piece
 of infrastructure -- so you better get the maintainance and safety story
 right:

    http://donsbot.wordpress.com/2010/08/17/practical-haskell/
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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 :)
 
 A quick question - import Process bombs on my GHCI(The Glorious
 Glasgow Haskell Compilation System, version 6.12.3) -what do I need to
 do for that?
 
 
 On Sun, Sep 5, 2010 at 11:12 PM, Don Stewart d...@galois.com wrote:
  Gaius:
  My usual rhetoric is that one-off, throwaway scripts never are, and
  not only do they tend to stay around but they take on a life of their
  own. Today's 10-line file munger is tomorrow's thousand-line ETL batch
  job on which the business depends for some crucial data - yet the
  original author is long gone and no-one dares modify in case it
  breaks. So it is just good sense to use sound practices from the very
  beginning.
 
  I gave a tech talk recently on using Haskell for scripting -- and it is
  built on the idea that today's throw away script is tomorrow's key piece
  of infrastructure -- so you better get the maintainance and safety story
  right:
 
     http://donsbot.wordpress.com/2010/08/17/practical-haskell/
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 
 
 
 -- 
 Regards,
 Kashyap
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-07 Thread C K Kashyap
Thanks Don!

On Tue, Sep 7, 2010 at 10:51 PM, Don Stewart d...@galois.com wrote:
 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 :)

 A quick question - import Process bombs on my GHCI(The Glorious
 Glasgow Haskell Compilation System, version 6.12.3) -what do I need to
 do for that?


 On Sun, Sep 5, 2010 at 11:12 PM, Don Stewart d...@galois.com wrote:
  Gaius:
  My usual rhetoric is that one-off, throwaway scripts never are, and
  not only do they tend to stay around but they take on a life of their
  own. Today's 10-line file munger is tomorrow's thousand-line ETL batch
  job on which the business depends for some crucial data - yet the
  original author is long gone and no-one dares modify in case it
  breaks. So it is just good sense to use sound practices from the very
  beginning.
 
  I gave a tech talk recently on using Haskell for scripting -- and it is
  built on the idea that today's throw away script is tomorrow's key piece
  of infrastructure -- so you better get the maintainance and safety story
  right:
 
     http://donsbot.wordpress.com/2010/08/17/practical-haskell/
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 



 --
 Regards,
 Kashyap





-- 
Regards,
Kashyap
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-06 Thread Stephen Tetley
On 6 September 2010 03:46, Mathew de Detrich dete...@gmail.com wrote:
 If they are perl programmers, they (should) understand perl very well. I
 would suggest to try explaining to them the obvious disadvantages of perl
 and the way that Haskell can cover those disadvantages without (much) of a
 compromise.

Now that's going to go down well...

Maybe the original poster might want to soak up the company culture
for a while before than telling co-workers how to do things.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-06 Thread Mathew de Detrich
I Think you misinterpreted what I said. I didn't say you should tell the
programmers how to code, I said you should show the perl coders how Haskell
has advantages over pearls without much cost

On 06/09/2010 5:21 PM, Stephen Tetley stephen.tet...@gmail.com wrote:

On 6 September 2010 03:46, Mathew de Detrich dete...@gmail.com wrote:
 If they are perl programme...
Now that's going to go down well...

Maybe the original poster might want to soak up the company culture
for a while before than telling co-workers how to do things.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
h...
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-06 Thread edgar klerks
Hi All,

Not a complete guide, but just something, which can help:

Perl6 is inspired by haskell. That was, how I end up by haskell. And I
believe a lot of people of the perl community got interested in haskell that
way. Maybe this works for some of collegues too. I still like perl, but
haskell is in many cases more productive. On the other hand perl has more
libs.

Greets,

Edgar
On Mon, Sep 6, 2010 at 12:50 PM, Mathew de Detrich dete...@gmail.comwrote:

 I Think you misinterpreted what I said. I didn't say you should tell the
 programmers how to code, I said you should show the perl coders how Haskell
 has advantages over pearls without much cost

 On 06/09/2010 5:21 PM, Stephen Tetley stephen.tet...@gmail.com wrote:

 On 6 September 2010 03:46, Mathew de Detrich dete...@gmail.com wrote:
  If they are perl programme...
 Now that's going to go down well...

 Maybe the original poster might want to soak up the company culture
 for a while before than telling co-workers how to do things.

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 h...


 ___
 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] help me evangelize haskell.

2010-09-05 Thread Ben Lippmeier

On 05/09/2010, at 2:38 AM, Michael Litchard wrote:

 I'll be starting a new job soon as systems tool guy. The shop is a
 perl shop as far as internal automation tasks go. But I am fortunate
 to not be working with bigots. If they see a better way, they'll take
 to it. So please give me your best arguments in favor of using haskell
 for task automation instead of perl, or awk or any of those scripting
 lanugages.

Try to avoid religious arguments like by using Perl you're living in a state 
of sin, and focus on look how much easier it is to do X in Haskell. 

Grandiose, hand-wavy assertions like strong typing leads to shorter 
development times and more reliable software don't work on people that haven't 
already been there and done that. When you try to ram something down someone's 
throat they tend to resist. However, if you can provide something tasty and 
appealing they'll eat it themselves. Write a nice program, show it to your Perl 
programmer, and if they also think it's nice -- then you've already won.

Ben.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-05 Thread Chris Eidhof
On 5 sep 2010, at 09:28, Ben Lippmeier wrote:

 
 On 05/09/2010, at 2:38 AM, Michael Litchard wrote:
 
 I'll be starting a new job soon as systems tool guy. The shop is a
 perl shop as far as internal automation tasks go. But I am fortunate
 to not be working with bigots. If they see a better way, they'll take
 to it. So please give me your best arguments in favor of using haskell
 for task automation instead of perl, or awk or any of those scripting
 lanugages.
 
 Try to avoid religious arguments like by using Perl you're living in a state 
 of sin, and focus on look how much easier it is to do X in Haskell. 
 
 Grandiose, hand-wavy assertions like strong typing leads to shorter 
 development times and more reliable software don't work on people that 
 haven't already been there and done that. When you try to ram something down 
 someone's throat they tend to resist. However, if you can provide something 
 tasty and appealing they'll eat it themselves. Write a nice program, show it 
 to your Perl programmer, and if they also think it's nice -- then you've 
 already won.

I've had success in situations with tight deadlines: the only way I got it done 
quickly and without bugs is by using Haskell (as opposed to PHP). Another place 
where you might have success is by writing a small compiler or interpreter for 
an internal language. Start small (in a niche, if you will) and expand upon 
that.

-chris___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-05 Thread Donn Cave
Quoth Ben Lippmeier b...@ouroborus.net,
...
 Grandiose, hand-wavy assertions like strong typing leads to
 shorter development times and more reliable software don't work
 on people that haven't already been there and done that. When you
 try to ram something down someone's throat they tend to resist.

Though, I think those sentiments can be appreciated when expressed 
properly.  I mean, I can talk about how nice it is when my programs
work the first time I run them, without necessarily being grandiose
or trying to ram something down anyone's throat.

I guess everyone's different - some Perl programmers might really
respond to a nice Haskell program, if it isn't gratuitously
incomprehensible.  Others may be more interested in the rationale
behind the language's features, and only from there find any motivation
to try to understand the syntax.

Of course it's a good idea to feign interest in their views on
software engineering, etc., but mostly it comes down to your charisma.
Never worked for me, but good luck!

Donn Cave, d...@avvanta.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-05 Thread Don Stewart
Gaius:
 My usual rhetoric is that one-off, throwaway scripts never are, and
 not only do they tend to stay around but they take on a life of their
 own. Today's 10-line file munger is tomorrow's thousand-line ETL batch
 job on which the business depends for some crucial data - yet the
 original author is long gone and no-one dares modify in case it
 breaks. So it is just good sense to use sound practices from the very
 beginning. 

I gave a tech talk recently on using Haskell for scripting -- and it is
built on the idea that today's throw away script is tomorrow's key piece
of infrastructure -- so you better get the maintainance and safety story
right:

http://donsbot.wordpress.com/2010/08/17/practical-haskell/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-05 Thread Andrew Coppin

Michael Litchard wrote:

I'll be starting a new job soon as systems tool guy. The shop is a
perl shop as far as internal automation tasks go. But I am fortunate
to not be working with bigots. If they see a better way, they'll take
to it. So please give me your best arguments in favor of using haskell
for task automation instead of perl, or awk or any of those scripting
lanugages


Rather than how can I convince them to use Haskell for everything?, 
how about just convincing them to use it on a case-by-case basis. It's 
plausible there are scenarios where Haskell is *not* the best thing to 
use. And if you just tirelessly evangelize Haskell, them one has to 
wonder who's the bigot. ;-)


(That said, I really hate Perl...)

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-05 Thread Mathew de Detrich
If they are perl programmers, they (should) understand perl very well. I
would suggest to try explaining to them the obvious disadvantages of perl
and the way that Haskell can cover those disadvantages without (much) of a
compromise.

Perl programs are either ones that are ridiculously short/concise, these are
one off scripts that become impossible to maintain (and even to read apart
from whoever coded the script). These perl scripts are typically shorter
then the equivalent Haskell ones. The other type of Perl scripts are the
ones that are fairly concise, and at least more maintainable/scalable. These
perl scripts tend to be the same size as the Haskell ones, except the
Haskell ones are type safe, have error checking and are much more
maintainable/scalable (the slideshow earlier with DonS shows this). Odds are
that the company probably has the latter of Perl scripts, so if you can show
them how Haskell can be just as excise (but not as extremely concise)
however have a lot more other benefits that will help a lot.

Another thing you can say is that Perl is a very extreme language in design
where as Haskell is more general. This means the one thing Perl does, it
does very well (expressing programming problems in the most concise/short
possible way) but it has to sacrifice for it massively in other areas which
end up costing much more in the long run. Most 'real' world problems do not
require that amount of brevity, considering the massive cost that Perl
brings for such a thing.

Also show them quickcheck as well

On Sun, Sep 5, 2010 at 2:38 AM, Michael Litchard mich...@schmong.orgwrote:

 I'll be starting a new job soon as systems tool guy. The shop is a
 perl shop as far as internal automation tasks go. But I am fortunate
 to not be working with bigots. If they see a better way, they'll take
 to it. So please give me your best arguments in favor of using haskell
 for task automation instead of perl, or awk or any of those scripting
 lanugages.
 ___
 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] help me evangelize haskell.

2010-09-05 Thread Alexander Solla


On Sep 5, 2010, at 7:46 PM, Mathew de Detrich wrote:

Another thing you can say is that Perl is a very extreme language in  
design where as Haskell is more general. This means the one thing  
Perl does, it does very well (expressing programming problems in the  
most concise/short possible way) but it has to sacrifice for it  
massively in other areas which end up costing much more in the long  
run. Most 'real' world problems do not require that amount of  
brevity, considering the massive cost that Perl brings for such a  
thing.


That doesn't sound right to me.  Perl's biggest weaknesses are  
traditionally:  (i) the syntax:  but those $'s and @'s are actually  
type annotations;  and (ii) There's More Then One Way to Do It:  the  
existence of multiple approaches to solving a problem, instead of an  
official obvious choice.  This means that every programmer on the  
team either has to KNOW all the possible ways to solve a problem with  
Perl, or the programming team has to CHOOSE one and make it policy  
-- effectively picking out the nicest bits and sticking to that sub- 
language.


Depending on your point of view, Haskell does not compare particularly  
favorably with respect to TMTOWTDI.  The whole Control.* hierarchy  
is the construction of custom control structures.  That's the whole  
point of glue languages.  You write custom control structures to  
support the chosen normal forms for expressing data and computations.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-04 Thread Vo Minh Thu
2010/9/4 Michael Litchard mich...@schmong.org:
 I'll be starting a new job soon as systems tool guy. The shop is a
 perl shop as far as internal automation tasks go. But I am fortunate
 to not be working with bigots. If they see a better way, they'll take
 to it. So please give me your best arguments in favor of using haskell
 for task automation instead of perl, or awk or any of those scripting
 lanugages.

Hi,

At a talk presented during a Ghent FPG meeting, someone explained how
they brought Ocaml to the work place. Basically, they made a drop-in
replacement for a C++ (or maybe was it C) library. Less code, same or
above performance.

Maybe they had also a good reason to rewrite the library (because it
was too big, or too difficult to maintain), not just as a proof that
Ocaml was better suited.

I guess that in your case, Perl for internal automation task, you
should find some little tool for which it would be acceptable to
dedicate some time rewriting it in Haskell.

Tell us how all this unfolds.

Cheers,
Thu
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


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

2010-09-04 Thread Gaius Hammond
My usual rhetoric is that one-off, throwaway scripts never are, and not only do 
they tend to stay around but they take on a life of their own. Today's 10-line 
file munger is tomorrow's thousand-line ETL batch job on which the business 
depends for some crucial data - yet the original author is long gone and no-one 
dares modify in case it breaks. So it is just good sense to use sound practices 
from the very beginning. 


One of the features of Perl is that it will try to work even if you make type 
errors (e.g. give it a scalar in place of a list, or a string instead of an 
int). One day, however, it WILL fail. Haskell finds these types of bugs 
upfront, and not when your pager goes off at 3am...


Cheers,


G

--Original Message--
From: Michael Litchard
Sender: haskell-cafe-boun...@haskell.org
To: haskell-cafe@haskell.org
Subject: [Haskell-cafe] help me evangelize haskell.
Sent: Sep 4, 2010 17:38

I'll be starting a new job soon as systems tool guy. The shop is a
perl shop as far as internal automation tasks go. But I am fortunate
to not be working with bigots. If they see a better way, they'll take
to it. So please give me your best arguments in favor of using haskell
for task automation instead of perl, or awk or any of those scripting
lanugages.
___
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] help me evangelize haskell.

2010-09-04 Thread Michael Litchard
I will be going into a situation where there are tasks that have yet
to be automated, so I will be going after that before re-writing
anything. But if I can come up with here's why, there will be less
eyebrows raised. Thanks for all feedback so far.

On Sat, Sep 4, 2010 at 10:21 AM, Gaius Hammond ga...@gaius.org.uk wrote:
 My usual rhetoric is that one-off, throwaway scripts never are, and not only 
 do they tend to stay around but they take on a life of their own. Today's 
 10-line file munger is tomorrow's thousand-line ETL batch job on which the 
 business depends for some crucial data - yet the original author is long gone 
 and no-one dares modify in case it breaks. So it is just good sense to use 
 sound practices from the very beginning.


 One of the features of Perl is that it will try to work even if you make type 
 errors (e.g. give it a scalar in place of a list, or a string instead of an 
 int). One day, however, it WILL fail. Haskell finds these types of bugs 
 upfront, and not when your pager goes off at 3am...


 Cheers,


 G

 --Original Message--
 From: Michael Litchard
 Sender: haskell-cafe-boun...@haskell.org
 To: haskell-cafe@haskell.org
 Subject: [Haskell-cafe] help me evangelize haskell.
 Sent: Sep 4, 2010 17:38

 I'll be starting a new job soon as systems tool guy. The shop is a
 perl shop as far as internal automation tasks go. But I am fortunate
 to not be working with bigots. If they see a better way, they'll take
 to it. So please give me your best arguments in favor of using haskell
 for task automation instead of perl, or awk or any of those scripting
 lanugages.
 ___
 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] help me evangelize haskell.

2010-09-04 Thread Jason Dagit
On Sat, Sep 4, 2010 at 5:53 PM, Michael Litchard mich...@schmong.org wrote:
 I will be going into a situation where there are tasks that have yet
 to be automated, so I will be going after that before re-writing
 anything. But if I can come up with here's why, there will be less
 eyebrows raised. Thanks for all feedback so far.

Perhaps give this talk:
  http://donsbot.wordpress.com/2010/08/17/practical-haskell/

Jason
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help with Bird problem 1.4.1

2010-05-18 Thread Daniel Fischer
On Tuesday 18 May 2010 21:49:50, R J wrote:
 Newbie trying to get through Bird.  Could someone provide a clean
 solution, with proof (so I can see how these proofs are laid out), to
 this: Given:
 f :: Integer - Integer
 g :: Integer - (Integer - Integer)
 h :: ...
 h x y =  f (g x y)
 Questions:
 a.  Fill in the type assignment for h.

h takes two arguments[1], feeds them to g and applies f to the result.
So the type of h must be

h :: a - b - c (or, equivalently, h :: a - (b - c)).

The overall result is the result of f, hence the final result type of h 
must be the result type of f, in other words, c = Integer.
The arguments of h are passed to g, hence the types of h's arguments must 
be the types of g's arguments, in other words, a = b = Integer, so

h :: Integer - Integer - Integer

If you don't get irritated by the parentheses in g's type (or if you're 
used to how functions work), it's very straightforward. 

 b.  Which of the following is true:   
 (i)   h = f . g

The type of (.) is

(.) :: (b - c) - (a - b) - (a - c)

Hence, if (f . g) is a well typed expression, f's type must be (b - c) and 
g's type must be (a - b).
Now, f :: Integer - Integer, giving b = Integer and c = Integer.
Further, g :: Integer - (Integer - Integer), giving a = Integer and 
b = (Integer - Integer).
We have conflicting resolutions of b, thus the expression (f . g) isn't 
well typed, in particular, (i) is false.

 (ii)  h x = f . (g x)

Firstly, if x :: Integer, then (f . (g x)) is a well typed expression. For, 
(g x) :: Integer - Integer, so now unifying the type of (g x) with the 
(a - b) from (.)'s type gives a = Integer and b = Integer.
Thus f and (g x) resolve b to the same type and we have

f . (g x) :: Integer - Integer

Now, the definition of (.) is
(u . v) y = u (v y).
Substituting u = f and v = (g x), we find
(f . (g x)) y = f ((g x) y).
Since function application is left-associative, we can also write ((g x) y) 
as (g x y) and find that indeed both sides of the equation give the same 
values for each argument y, so they are the same. (ii) is true.

 (iii) h x y = f . (g x y)

Now, g x y :: Integer. Integer can't be unified with (a - b), so (g x y) 
is not a suitable argument for (.) and
f . (g x y) is not a well typed expression, in particular, (iii) is false.




[1] Actually, every function takes exactly one argument. Some functions, 
however, return functions, which then take another argument and return 
possibly another function, which then takes another argument, ...

But, if

fun :: a - (b - (c - d))

, it would be too cumbersome to say fun is a function which takes an 'a' 
as argument and returns a function which takes a 'b' as argument and 
returns a function which takes a 'c' as argument and returns a 'd', so 
most of the time we abbreviate that to fun is a function taking three 
arguments, an 'a', a 'b' and a 'c' and returns a 'd'.
And, unless there are reasons not to, usually the parentheses in the 
function type are omitted, like the parentheses in the function 
application.
Properly parenthesised, the definition of h above would be

h x y = f ((g x) y).
But since function application associates to the left and the function type 
(-) associates to the right, the parentheses aren't necessary.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help debugging code broken after upgrading debian to GHC 6.12: invalid argument

2010-05-15 Thread Daniel Fischer
On Saturday 15 May 2010 15:18:28, Brandon Simmons wrote:
 On May 14, 2010, at 20:24 , Brandon Simmons wrote:
  The other baffling thing is this: if the debugging line 426 is
  uncommented, then even running:
 
 $ runghc Befunge.hs --quiet mycology.b98
 
  ...will fail. But all we're doing is a call to `putStr`! Why would
  that trigger an error?! Maybe there was a bug in my code that was
 
  GHC 6.12's runtime handles input and output encoding, instead of
  simply truncating Chars; my guess is it's locale-related.  And sure
  enough, I see several non-ASCII characters in mycology.b98 which are
  likely to do the wrong thing if the runtime doesn't know which
  character set to use.

 Thanks, that makes a lot of sense. Is there something I can read to
 enlighten myself as to how I would go about getting my program to be
 liberal about non-ascii characters in a file?

Non-ASCII characters aren't a problem per se. The problem is that by 
default, GHC reads files as encoded by the system locale. If the file is 
encoded in a different way - boom.
You can set the encoding of a handle, so that the file's contents are 
interpreted e.g. as latin1 encoded (or cp1252 or utf-16, ...).
Or you can iconv your files to your system's locale (probably utf-8).


 Also, I noticed yesterday that

 $ cabal list --installed

 shows the 'old-locale' package:

 * old-locale
 Synopsis: locale library
 Latest version available: 1.0.0.2
 Latest version installed: 1.0.0.2
 License:  BSD3

 I'm not sure if that could be part of the issue, or whether that is
 normal.

That's normal. old-locale comes with GHC.


 Thanks again,
 Brandon Simmons
 http://coder.bsimmons.name/

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help debugging code broken after upgrading debian to GHC 6.12: invalid argument

2010-05-14 Thread Brandon S. Allbery KF8NH

On May 14, 2010, at 20:24 , Brandon Simmons wrote:

The other baffling thing is this: if the debugging line 426 is
uncommented, then even running:

   $ runghc Befunge.hs --quiet mycology.b98

...will fail. But all we're doing is a call to `putStr`! Why would
that trigger an error?! Maybe there was a bug in my code that was



GHC 6.12's runtime handles input and output encoding, instead of  
simply truncating Chars; my guess is it's locale-related.  And sure  
enough, I see several non-ASCII characters in mycology.b98 which are  
likely to do the wrong thing if the runtime doesn't know which  
character set to use.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help debugging code broken after upgrading debian to GHC 6.12: invalid argument

2010-05-14 Thread Daniel Fischer
On Saturday 15 May 2010 02:53:43, Brandon S. Allbery KF8NH wrote:
 On May 14, 2010, at 20:24 , Brandon Simmons wrote:
  The other baffling thing is this: if the debugging line 426 is
  uncommented, then even running:
 
 $ runghc Befunge.hs --quiet mycology.b98
 
  ...will fail. But all we're doing is a call to `putStr`! Why would
  that trigger an error?! Maybe there was a bug in my code that was

 GHC 6.12's runtime handles input and output encoding, instead of
 simply truncating Chars; my guess is it's locale-related.  And sure
 enough, I see several non-ASCII characters in mycology.b98 which are
 likely to do the wrong thing if the runtime doesn't know which
 character set to use.

Yup. Converting mycology.b98 to utf-8 makes it run.
However, why does it run with --quiet on the original file??
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] help with Haskell programming

2010-04-18 Thread Thomas Davie
I'm not certain exactly what you mean, but I *think* you mean:

func :: (a - Bool) - (a - Bool)
func = (not .)

Bob

On 18 Apr 2010, at 16:35, Mujtaba Boori wrote:

 Hello I am kinda newbie in Haskell you can help help me with some programming
 
 I am trying to make function like for example 
 
 func :: (a - Bool) - (a - Bool)
 
 this function make calculation  and return bool . I want to be able to make 
 bool True when It is False and False when it is True while returning the a. 
 
 Thank you 
 
 -- 
 Mujtaba Ali Alboori
 ___
 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] help with Haskell programming

2010-04-18 Thread Keith Sheppard
Hello Mujtaba,

I wonder is this homework? If that's the case there is nothing wrong
with asking homework related questions but they should probably be
marked as such.

I think the most straight forward solution will use function
composition (.) and the (not) function

-keith

On Sun, Apr 18, 2010 at 11:35 AM, Mujtaba Boori mujtaba.bo...@gmail.com wrote:
 Hello I am kinda newbie in Haskell you can help help me with some
 programming
 I am trying to make function like for example
 func :: (a - Bool) - (a - Bool)
 this function make calculation  and return bool . I want to be able to make
 bool True when It is False and False when it is True while returning the a.
 Thank you
 --
 Mujtaba Ali Alboori

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe





-- 
keithsheppard.name
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help mixing pure and IO code

2009-11-30 Thread Eric Dedieu
 There's a nice approach to this problem which is described
 and implemented in the MonadPrompt package[1].

Thanks a lot for this link. The guessing game example linked to from
the documentation is still very hard to understand (I'm still struggling
with monads), but it seems to fill my needs.

Still more importantly to me, I understand that anyhow  if I intend to
use IO or random numbers, I must design my strategy from the beginning
as encapsulated in a monad. Something like:

class (Monad m) = Strategy m a where ...

Cheers,
Eric
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help mixing pure and IO code

2009-11-30 Thread klondike
Eric Dedieu escribió:
 Still more importantly to me, I understand that anyhow  if I intend to
 use IO or random numbers, I must design my strategy from the beginning
 as encapsulated in a monad. Something like:

 class (Monad m) = Strategy m a where ...
   
That's not true at all, you can always pass this data to your strategy
entry points and let haskell get it lazily, though it is not as
intuitive as other aproaches,

Ie. I need to get the next pick for my IA so I can use a function called
get IA wich would take as arguments a random seed (or an infinite vector
of random numbers using laziness ;) ) and the previous user inputs and
strategy outputs.

Of course this is just retarding the monadification of the function as
soon or later you'll have to embed it into a IO monad to get the desired
results. Anyway, making the strategies completely deterministic can also
be useful when debugging.



signature.asc
Description: OpenPGP digital signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help mixing pure and IO code

2009-11-30 Thread Eric Dedieu
  Still more importantly to me, I understand that anyhow  if I intend
  to use IO or random numbers, I must design my strategy from the
  beginning as encapsulated in a monad. Something like:
 
  class (Monad m) = Strategy m a where ...

 That's not true at all, you can always pass this data to your strategy
 entry points and let haskell get it lazily, though it is not as
 intuitive as other aproaches,

That seems exactly what I had tried to do (and
failed) in my original code.

The Fixed type was to provide the list of moves:

 data Fixed = Fixed [Move] deriving Show

and instanciate a strategy that ignores the game to
make decisions, just return the provided moves, then zeroes if ever
exhausted:

 instance Strategy Fixed where
 proposeNext game s = case s of
Fixed [] - (0, Fixed [])
Fixed (x:xs) - (x, Fixed xs)

but when using an IO Fixed, the questions were not repeated lazily as
needed, as if the list of moves was entirely evaluated; so this failed:

 askUntil :: String - IO Fixed
 askUntil name = liftM Fixed (sequence $ repeat askio)
 where askio = putStr (name ++ , pick a number: )  readLn

I thought that sequencing [IO Move] to IO [Move] was what breaked
lazyness, so I tried other ways to turn an [IO Move] into a IO
Strategy, and failed.

If I did not interpret correctly why this was not lazy, or if it is
indeed possible to do otherwise can you please show me how?

Thanks,
Eric
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Help mixing pure and IO code

2009-11-30 Thread Hector Guilarte
One time I needed to do use a random number in some places of a completly
pure program so I made a infinite list of random numbers and passed it
around all the time in the functions as they where called, using the head of
the list I passed to the function whenever I needed a random number and
returning a tuple which it's second element was the tail of the random
numbers list e.g.

f:: [int] - (a,[Int])
f randomList =
let usedRandomNumber = g $ head randomList
in (usedRandomNumber,(tail randomList))

or even something like:
f:: [int] - (a,[Int])
f randomList =
let (usedRandomNumber,newRandomList) = g randomList
in (usedRandomNumber,newRandomList)

where g:: [int] - (a,[Int])


The actuall code for doing this is: (Warning, it uses unsafePerformIO, just
for the seed of the random Generator, I really don't think it would do any
harm)

rand :: (RandomGen g, Random a) = (a,a) - g - [a]
rand range gen = as
 where  (a,b) = split gen  -- create two separate generators
as = randomRs range a  -- one infinite list of randoms

seed :: Int
seed = fromInteger (unsafePerformIO getCPUTime)

mygen  = mkStdGen seed

infinito:: (Num t,Random t) = [t]
infinito = [ x | x - rand (1,100) mygen]


infinito is the function that you need to call in your code that will give
you the infinite list of random numbers which will be evaluated lazyly...

Hope you can use this...

About the prompt thing, that you'll have to wait for another answer or use
what they have already told you,


Greetings,

Hector Guilarte




On Mon, Nov 30, 2009 at 8:13 PM, Eric Dedieu papa.e...@free.fr wrote:

   Still more importantly to me, I understand that anyhow  if I intend
   to use IO or random numbers, I must design my strategy from the
   beginning as encapsulated in a monad. Something like:
  
   class (Monad m) = Strategy m a where ...
  
  That's not true at all, you can always pass this data to your strategy
  entry points and let haskell get it lazily, though it is not as
  intuitive as other aproaches,

 That seems exactly what I had tried to do (and
 failed) in my original code.

 The Fixed type was to provide the list of moves:

  data Fixed = Fixed [Move] deriving Show

 and instanciate a strategy that ignores the game to
 make decisions, just return the provided moves, then zeroes if ever
 exhausted:

  instance Strategy Fixed where
  proposeNext game s = case s of
 Fixed [] - (0, Fixed [])
 Fixed (x:xs) - (x, Fixed xs)

 but when using an IO Fixed, the questions were not repeated lazily as
 needed, as if the list of moves was entirely evaluated; so this failed:

  askUntil :: String - IO Fixed
  askUntil name = liftM Fixed (sequence $ repeat askio)
  where askio = putStr (name ++ , pick a number: )  readLn

 I thought that sequencing [IO Move] to IO [Move] was what breaked
 lazyness, so I tried other ways to turn an [IO Move] into a IO
 Strategy, and failed.

 If I did not interpret correctly why this was not lazy, or if it is
 indeed possible to do otherwise can you please show me how?

 Thanks,
 Eric
 ___
 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


  1   2   3   >