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


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

2013-06-16 Thread Takayuki Muranushi
In an attempt to understand why cata- and anamorphisms are considered so
important, I found multiple implications that you can write any recursive
functions in terms of nonrecursive functions and ana, cata (am I right
here?) so I'm trying to practice the rewrite by a few functions. I'm
following a 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
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] help understanding zlib space leak

2013-05-05 Thread diego souza
Dear haskellers,

I'd like assistance figuring out a strange space leak using zlib
package.

To make it easier to reproduce I've come up with the following snippet
that pretty much resumes up the problem I'm trying to solve:

 -- omitting imports and function signatures
 encode = compress . L.fromChunks
  
 main = do { hSetBinaryMode stdout True
   ; hSetBinaryMode stdin True
   ; hSetBuffering stdin NoBuffering
   ; hSetBuffering stdout NoBuffering
   ; loop []
   }
  where loop buff
  | length buff == 64 = L.hPut stdout (encode buff)  loop []
  | otherwise = do { eof - hIsEOF stdin
   ; when (not eof) (fmap (: buff) (B.hGetSome 
 stdin 512) = loop)
   }

N.B.: Removing the `compress' function from the above code also removes the
  space leak.

Now, feeding the above program with ~8GB worth of binary data:

 $ uname -a
Linux mephisto.localhost.localdomain 3.8.7-1-ARCH #1 SMP PREEMPT Sat Apr 13 
09:01:47 CEST 2013 x86_64 GNU/Linux
 $ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3
 $ ghc -W -Wall -rtsopts --make -O2 test.hs
 $ sudo dd if=/dev/sda bs=4K count=2048K | ./test +RTS -M1M -s /dev/null
...
8589934592 bytes (8.6 GB) copied, 277.263 s, 31.0 MB/s
...
   2 MB total memory in use (0 MB lost due to fragmentation)
...

Which is fine. However, monitoring the RSS size is a different story:

 $ while pidof test; do ps -o rss= -p $(pidof test); done | tail
16967
25620
16967
25628
16967
25628
16967
25628
16967  # ~16M
0

I know the RSS usually overestimates the memory consumption but the
problem is that it is forever growing.

The following I found very intriguing:

  * `+RTS -hc` gives me no hint about whats wrong [at least I couldn't see one];
  * `+RTS -M1M` doesn't produce an error;
  * removing the `compress' functions makes the problem disappear;

I couldn't figure these out and I don't think this is matter of
strictness, though. Has anyone seen this before?

Thanks in advance,
~dsouza

___
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


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

2013-02-27 Thread oleg

Dmitry Kulagin wrote:
 I try to implement typed C-like structures in my little dsl.

HList essentially had those
http://code.haskell.org/HList/

 I was unable to implement required type function:
 type family Find (s :: Symbol) (xs :: [(Symbol,Ty)]) :: Ty
 Which just finds a type in a 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
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


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

2013-02-26 Thread Dmitry Kulagin
Hi,

I try to implement typed C-like structures in my little dsl.
I was able to express structures using type-level naturals (type Ty is
promoted):

 data Ty = TInt | TBool | TStruct Symbol [Ty]

That allowed to implement all needed functions, including type-level
function:

 type family Get (n :: 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


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


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

2013-01-06 Thread Thomas Bereknyei
I have had issues like this with modifySTRef before. Try to make a strict
version modifySTRef'

If memory serves, something like this worked for me.
modifySTRef' r f =
  do
a - readSTRef r
writeSTRef r $! f a
___
Haskell-Cafe mailing list
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


[Haskell-cafe] Help optimize fannkuch program

2012-12-02 Thread Branimir Maksimovic

Well, playing with Haskell I have literally trasnlated my c++ program 
http://shootout.alioth.debian.org/u64q/program.php?test=fannkuchreduxlang=gppid=3and
 got decent performance but not that good in comparisonwith c++ On my machine 
Haskell runs 52 secs while c++ 30 secs.(There is Haskell entry that is fastest 
but unfortunately does not runs on test machine is on par with 
c++http://shootout.alioth.debian.org/u64q/program.php?test=fannkuchreduxlang=ghcid=3)There
 is something which I have missing since programsare identical.Aa with previous 
entries you gurus here helped a lot in both helpand learning experience.I 
simply love Haskell ;)I plan to contribute this program as it is much faster 
than current runningentry 
http://shootout.alioth.debian.org/u64q/program.php?test=fannkuchreduxlang=ghcid=2even
 if it is multithreaded and my is not.
This is program:
{-# LANGUAGE CPP, BangPatterns #-}{-  The Computer Language Benchmarks Game
http://shootout.alioth.debian.org/
contributed by Branimir Maksimovic
-}
import System.Environmentimport Text.Printfimport Data.Bits
import qualified Data.Vector.Unboxed.Mutable as VMimport qualified 
Data.Vector.Generic.Mutable as VGimport qualified Data.Vector.Unboxed as V
main = do   n - getArgs = readIO.head(checksum,maxflips) - fannkuch 
n   printf %d\nPfannkuchen(%d) = %d\n checksum n maxflips
fannkuch n = do !perm -  V.unsafeThaw $ V.fromList [1..n]  !tperm -  
VG.new n !cnt -  VG.replicate n 0   let loop :: Int - Int 
- Int - IO(Int,Int)loop !c !m !pc = do !b 
- next_permutation perm n cnt   if b == False then return 
(c,m) else do VM.unsafeCopy 
tperm perm!flips -  count_flips tperm 0
  loop (c + (if pc .. 1 == 0 then flips else -flips))  
   (max m flips)   
(pc+1) r - loop 0 0 1 return r

next_permutation :: VM.IOVector Int - Int - VM.IOVector Int- 
IO(Bool)next_permutation !perm !n !cnt =do  !i - loop 1
if(i = n)  then return False   
else do !v - VM.unsafeRead cnt i   
VM.unsafeWrite cnt i (v+1)  return True 
where   loop :: Int - IO(Int)  loop !i 
| i  n = do  !tmp 
- VM.unsafeRead perm 0let  
 rotate :: Int - IO()   rotate !j =
 if j = i  
 then do 
VM.unsafeWrite perm i tmp   
return ()   else do 
!v - VM.unsafeRead perm (j+1)  
VM.unsafeWrite perm j v 
rotate (j+1)  rotate 0  
  !v - VM.unsafeRead cnt i 
  if v = i then do 
VM.unsafeWrite cnt i 0  
loop (i+1)  else return i   
| otherwise = return i  
count_flips :: VM.IOVector Int - Int - IO(Int)count_flips !tperm !flips = do  
!f - VM.unsafeRead tperm 0 if f == 1   then
return flipselse do VG.reverse $ 
VM.unsafeSlice 0 f tperm   count_flips tperm (flips+1)


  ___
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


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

2012-10-23 Thread José A. Lopes

Hey everyone,

I changed my code I now I get the following error message
Main: thread blocked indefinitely in an MVar operation

Before the change, I was using the State monad with runState.
Then, I changed the code to use the StateT monad transformer wrapped 
around IO monad and runStateT.

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.


Here are some specs:
ghc 7.4.2
mtl 2.1.1

If you need any other information please don't hesitate to ask.
Any help is greatly appreciated!

Cheers,
José

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


[Haskell-cafe] Help me with space leaks

2012-09-26 Thread Alexey Uimanov
Hello. I am trying to write some thing in haskell and i need fast
storage to store and select this things from storage.
https://github.com/s9gf4ult/projs/tree/master/haskell/teststorage

I am writing simple testing package to determine my needs and select
the fastest storage and i have encountered problems.

Firstly i decided to check out postgresql-simple, but when i am doing
executeMany i see space leaks, here is the picture
http://bayimg.com/NAdjHAaeA
http://bayimg.com/NADjKAAea
I dont fully understand what is happening here, but i belive this is
because of lazy consuming of executeMany or something. So things im
trying to insert do not calculate one by one, but this is creating
many thunks for calculate them.

I would understand how to narrow the cause of this problem and create
more strict function executeMany which would work in constant space
(or space of data).

Here the insertMany from postgresql-simple

executeMany :: (ToRow q) = Connection - Query - [q] - IO Int64
executeMany _ _ [] = return 0
executeMany conn q qs = do
  result - exec conn = formatMany conn q qs
  finishExecute conn q result

And this is not looks like a problem case go to formatMany

formatMany :: (ToRow q) = Connection - Query - [q] - IO ByteString
formatMany _ q [] = fmtError no rows supplied q []
formatMany conn q@(Query template) qs = do
  case parseTemplate template of
Just (before, qbits, after) - do
  bs - mapM (buildQuery conn q qbits . toRow) qs
  return . toByteString . mconcat $ fromByteString before :
intersperse (fromChar ',') bs ++
[fromByteString after]
Nothing - fmtError syntax error in multi-row template q []

Here bs is the map of bs and must stay lazy evaluated
and here we see mconcat which must be strict i think, and if i am
right so problem must disapear whan i replace it with strict mconcat

mconcat' :: (Monod a) = [a] - a
mconcat' [] = mempty
mconcat' (x:xs) = x `seq` (mappend x $ mconcat' xs)

but it doesnt.
I assume i must write the same for deepseq to realy calculate each
parameter up to value. But if so, this must touch several projects
such as blaze and maybe bytestring because of the need to make NFData instances.
How to solve this problem right - way ? Maybe haskell have elegant
solution for this ?

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


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

2012-09-12 Thread Alfredo Di Napoli
Hi everyone,

If this mail sound strange to you, you are free to ignore it.

My name is Alfredo Di Napoli and I'm a 24-year-old programmer from
Rome, Italy. I've graduated in May and I'm currently working as an intern
for a company involved in the defence field.

In my spare time, though, I study 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


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


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

2012-06-28 Thread Michael Snoyman
Hi all,

I'm just about ready to make the 0.5 release of conduit. And as usual,
I'm running up against the hardest thing in programming: naming
things.

Here's the crux of the matter: in older versions of conduit, functions
would have a type signature of Source, Sink, or Conduit. For example:

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.

Michael

[1] For example, maybe we want to produce `conduitFiles ::
MonadResource m = Conduit FilePath m ByteString`
[2] This problem exists to a smaller extent in conduit 0.4. This is
the purpose of the sinkToPipe function.
[3] 
https://github.com/snoyberg/conduit/blob/52d7bc0b551b877de92be4c87f933e3ffb1bb9f6/conduit/Data/Conduit/Internal.hs#L132
[4] 
https://github.com/snoyberg/conduit/blob/a853141d7b9eed047c7cc790979f73a346740ea0/conduit/Data/Conduit.hs#L403

___
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


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

2012-01-27 Thread Johannes Waldmann
Dear all,

I can't quite get safecopy to work with acid-state:

old version of code :

data T =  T Foo
$(deriveSafeCopy 0 'base ''T)

new version :

data T_orig = T_orig Foo
$(deriveSafeCopy 0 'base ''T_orig)
data T = T Foo Bar
$(deriveSafeCopy 0 'extension ''T)
instance Migrate T where type MigrateFrom T = T_Orig ...

but when my (new) application reads the state from disk
(written by the old application) I get
Could not parse saved checkpoint due to the following error:
Failed reading: Duplicate version tags: [0,0]

When I change the version number in deriveSafeCopy, I get
Failed reading: safecopy: Map: Cannot find getter associated
with this version number: Version {unVersion = 2}

I don't even know where the 2 comes from.

Any hints appreciated - J.W.



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


[Haskell-cafe] Help understanding Haskell runtime costs

2011-08-08 Thread Thiago Negri
Hello all,

I'm relatively new to Haskell and trying to solve some online judge's
problems in it.
One of the problems is to say if a given sentence is a tautogram or not.
A tautogram is just a sentence with all the words starting with the same letter.

My first try (solution is ok) was to do it as 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

toStr :: Bool - [Char]
toStr True = Y
toStr False = N

isTautogram :: [[Char]] - Bool
isTautogram (x:[]) = True
isTautogram (x:xs) = all ((== firstChar) . toLower . head) xs
where firstChar = toLower . head $ x
-- code end

I tried to profile the code, but didn't find anything useful.
My bet is that all this words . lines is consuming more memory than
necessary, maybe saving space for the lines already processed.
Then I tried a some-what tail-call function, consuming one line at
each iteration:

-- code start
import Data.Char (toLower)

main :: IO ()
main = getLine = mainLoop

mainLoop :: [Char] - IO ()
mainLoop s | (head s) == '*' = return ()
   | otherwise   = (putStrLn . toStr . isTautogram . words
$ s)  main

toStr :: Bool - [Char]
toStr True = Y
toStr False = N

isTautogram :: [[Char]] - Bool
isTautogram (x:[]) = True
isTautogram (x:xs) = all ((== firstChar) . toLower . head) xs
where firstChar = toLower . head $ x
-- code end

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

Thanks,
Thiago.

___
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
 

[Haskell-cafe] Help

2011-06-24 Thread Stoyan Peev
Hello all,

I am experiencing some issues to do my course task in university.

I have to write a calculator- function in Haskell. The function
argument is a list of strings and also form such list, as each string
of the argument made definite action:
- If the string has the form of an arithmetic _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

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


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


[Haskell-cafe] help with dynamic load

2011-03-25 Thread Rob Nikander
Hi all,

I'm trying to use the 'plugins' package.  Since I already posted to
stackoverflow I'll just link to that.  I posted a simple program that
I thought would work, but mostly doesn't.   Any pointers, appreciated.

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

thanks,
Rob

___
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


[Haskell-cafe] Help optimising a Haskell program

2011-03-21 Thread David MacIver
Hi,

I have a Haskell program I'm trying to optimise, and could use some assistance.

It's for rank aggregation - taking a bunch of partial rankings of some
items from users and turning them into an overall ranking (aka That
thing that Hammer Principle does).

The code is here: https://github.com/DRMacIver/hs-rank-aggregation.
The interesting code lives in the Algorithms.RankAggregation module.

The sample data I'm running it on is samples/electornot (voting data
from http://electornot.org.uk/).  Here's a profile:
https://gist.github.com/1ee9356f45330e9f8caa

Here's a recent profile: https://gist.github.com/1ee9356f45330e9f8caa

It's doing pretty well on this data, in that it's taking 8 seconds for
180k records (down from about 80 seconds earlier today) on my
computer, but I'd like it to be faster - ideally under a second.
Admittedly this is an arbitrary figure and I will just move the goal
posts if I achieve it, but it would still be nice. :-)

I suspect that it may be hitting the limits of what can be improved
without actually changing the algorithm (which I'm open to doing, but
not if it makes the results significantly worse), but the last 3 or 4
times I've thought that it was shortly followed by an optimisation
which halved the runtime or better. In particular the most likely
culprit for improvement is to deal with the fact that it allocates
nearly 5GB of data (that appears to be mostly transient - watching the
process as it runs the memory usage never seems to raise above 150MB,
which is large but unproblematic). The biggest culprit for this is
divideAndConquer which is probably generating a silly number of
intermediate lists, but it's not obvious how to fix that - maybe by
making the tree structure in the recursion more explicit? Don't know.
Suggestions very welcome.

Regards,
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-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


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

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

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


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


[Haskell-cafe] help for the usage on mfix

2011-02-22 Thread Gang Yu
hello cafe,

  I just want to do cursion to a fixpoint in an IO function, I write sth.
like this,

handle_ar::(Set String,Set String)-FilePath- IO (Set String, Set String)
handle_ar (def,undef) ar=do
  let gs = def
  gu = undef
  syms - liftM (map (\x - (symb x, x))) $ defined_syms ar
  usyms - liftM (map (\x - (symb x, x))) $ undefined_syms ar
  mfix (\(gs,gu) - do
   case find_obj gu usyms of Nothing - return (gs,gu)
 Just z -
   do
 let
   fout = fromList . map fst .
filter ((== (objf z)) . objf . snd)
   ls = fout syms
   lu = fout usyms
 handle_obj_ar (gs,gu) (ls,lu))
What I want to express is:

gs and gu are initiliazed to def and undef, then do recursion until
find_obj gu usyms is nothing, i.e, (gs,gu) reaches a fixpoint (suppose
handle_obj_ar always change the pair).

I am not sure I am on the right track since there is no room for def and
undef stand in the function.

Anyone can help?

thanks a lot.

Gang
___
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


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

2011-02-08 Thread C K Kashyap
Hi,
I need to convert IOArray to bytestring as shown below -

import Data.Array.IO
import Data.Binary.Put
import qualified Data.ByteString.Lazy as BS
import Data.Word

main = do
arr - newArray (0,9) 0 :: IO (IOArray Int Int)
let bs=toByteString arr
return ()

How can I implement the 'toByteString' function?

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


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

2010-12-23 Thread JP Moresmau
Hello all, sorry I must have taken my stupid pills this morning, I cannot
get the following code to compile, what am I missing?

data MyState=MyState Integer
newState:: (RandomGen g) = RandT g IO MyState
newState = do
 time-liftIO getCPUTime
 rand-getRandomR (1,6)
 return $ MyState (time+rand)

newStateIO :: IO MyState
newStateIO = do
r-getStdGen
evalRandT newState r

- Could not deduce (MonadIO (RandT g IO))  from the context (RandomGen
g)  arising from a use of `liftIO' at ...:4:15-31
Possible fix:
  add (MonadIO (RandT g IO)) to the context of
the type signature for `newState'
  or add an instance declaration for (MonadIO (RandT g IO)) Pirates.hs
/Pirates/src line 167 Problem

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
= 
MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO
 
(RandThttp://hackage.haskell.org/packages/archive/MonadRandom/0.1.6/doc/html/Control-Monad-Random.html#t:RandT
g
m)

And the MonadIO docs say:
Instances:
MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO
 
IOhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/System-IO.html#t:IO
So it looks to me it should work!
I've also tried to replace IO by MonadIO m= in the signature, or remove all
signatures. No joy.

Thanks for any help.

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


[Haskell-cafe] Help with lhs2TeX

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


___
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


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

2010-12-06 Thread Brandon Simmons
Hi all,

I gave myself until this evening to figure this out on my own, and
time is up! Hopefully this makes for a good discussion, though the
idea could be dumb.

What I'm trying to do is define a state monad in which the passed
state can change type during the computation. The only constraint is
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


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


[Haskell-cafe] Help me TH code.

2010-10-26 Thread Andy Stewart
Hi all,

I want use TH write some function like below:

  data DataType = StringT
| IntT
| CharT

  parse :: [(String,DataType)] - (TypeA, TypeB, ... TypeN)

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

will return:

  (string, 001, 'c')

So how to use TH write 'parse' function? 

Thanks!

  -- Andy

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


[Haskell-cafe] HELP

2010-10-21 Thread Yaadallah Khan

I am Studying for an exam, and i have just come accross the following 3 
questions, i am not familiar with the functions, therefore i would appreciate 
any help.
!! i have already created painting 2  3 all i need is the 3 functions, for the 
three different tasks as shown below. the functions are the showPic, sizeRaw 
and isPic.
questions are:
1)  – Define showPic :: Canvas - IO () for displaying pictures on theterminal. 
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 findingout 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 
particularnecessary condition which items of type Canvas must satisfy (full 
orraw). The condition you should check for is whether all the ‘rows’ ofthe 
input have the same length. (It may be assumed that the inputof isPic is of 
type Canvas.) Examples:
Cw2010 isPic (painting 3)TrueCw2010 isPic (painting 4)False
Suggestion. I found it useful in my implementation to define and usehere the 
auxiliary function isEqual :: [Int] - Bool; example:
Cw2008 isEqual [8,8,8,8]TrueCw2008 isEqual [8,8,4,8]FalseYou may wish to 
define and use isEqual in your implementation ofisPic too.  
   ___
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


[Haskell-cafe] Help us test gtk2hs darcs!

2010-09-27 Thread Andy Stewart
Hi all,

We have add many APIs in gtk2hs darcs, and ready to release
gtk2hs-0.12.0

Please help us test gtk2hs darcs, we can fix it before release
gtk2hs-0.12.0

You can get gtk2hs darcs with below command:

   darcs get code.haskell.org/gtk2hs

Please send any bug report to 

   gtk2hs-us...@lists.sourceforge.net

Thanks!

   -- Gtk2hs Team

___
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


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

2010-09-26 Thread rgowka1
Type signature would be Int - [Double] - [(Double,Double)]

Any thoughts or ideas on how to calculate a n-element moving average
of a list of Doubles?

Let's say [1..10]::[Double]

what is the function to calculate the average of the 3 elements?

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

(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
..
___
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


  1   2   3   4   >