Gregory Guthrie | 1 Feb 05:12
Favicon
Gravatar

mailing list question

I notice that the mailing list digest form is text only, so special symbols (Greek – alpha, beta, ..) all get mangled into “?”.

This is not so common on the Beginners list, but not infrequent on the Café list.

 

To find the original version, one needs to go to the archives, but they are indexed by date, and the digest is by Vol, No, Topic.

 

So,

Is there any way to get an HTML version of the digest?

And/or, to add some indexing to the archives? (an indexed page into the archives?)

 

I presume the answer to these is no, since I did not see any such options on the mailman archive page;

so likely this is just either a comment or suggestion, or both.  J

 

 

David Jacobs | 1 Feb 07:46

Re: mailing list question

Or how about UTF-8 plain text?

On Jan 31, 2012, at 8:12 PM, Gregory Guthrie <guthrie <at> mum.edu> wrote:

I notice that the mailing list digest form is text only, so special symbols (Greek – alpha, beta, ..) all get mangled into “?”.

This is not so common on the Beginners list, but not infrequent on the Café list.

 

To find the original version, one needs to go to the archives, but they are indexed by date, and the digest is by Vol, No, Topic.

 

So,

Is there any way to get an HTML version of the digest?

And/or, to add some indexing to the archives? (an indexed page into the archives?)

 

I presume the answer to these is no, since I did not see any such options on the mailman archive page;

so likely this is just either a comment or suggestion, or both.  J

 

 

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://www.haskell.org/mailman/listinfo/beginners
Ovidiu Deac | 2 Feb 03:28
Picon

unchecked exceptions as side effects

In this video Erik Meijer talks about side effects: https://www.youtube.com/watch?v=UuamC0T3hv8&t=6m and unchecked exceptions as side effects.

I tried to read the paper "Unchecked Exceptions can be Strictly More Powerful than Call/CC" but I got lost pretty quick.

Can somebody explain the matter nicely?

Thanks,
ovidiu

Zhi-Qiang Lei | 2 Feb 17:16
Picon

Is foldr slow?

Hi,

When I refactor my Segmented Seive of Eratosthenes, I'm puzzled by the performance of "foldr".
Here is my original code. I realized that "sieveWith"(Integral a => ([a], [a]) -> ([a], [a]), it takes a tuple with sieving primes and prime candidates, and remove all multiplies of sieving primes in candidates, at last return a tuple with blank sieving primes and a pure primes list) in "primesFromTo" is not much readable and can be replaced by "foldr".

But when I did, I find it would take about 5 seconds to sieve primes between 999900000 and 1000000000, whereas the original one just takes 1.6 
seconds. The "sieveWith" function is the only place I change. I also have tried foldr', which does not much help. Is foldr slow? Or did I make any 
mistake? Thanks.

=== Origin (./main < data1.txt  1.45s user 0.11s system 99% cpu 1.562 total) ===
{-# OPTIONS_GHC -O2 #-}

import Data.List
import System.IO

minus (x:xs) (y:ys) = case (compare x y) of 
           LT -> x : minus  xs  (y:ys)
           EQ ->     minus  xs     ys 
           GT ->     minus (x:xs)  ys
minus  xs     _     = xs

intSqrt :: Integral a => a -> a
intSqrt = floor . sqrt . fromIntegral

primesTo :: Integral a => a -> [a]
primesTo x = 2 : sieve [3, 5 .. x] where
    sieve ns <at> (n : rs)
        | n <= intSqrt x    = n : sieve (rs `minus` [n * n, n * (n + 2) .. x])
        | otherwise         = ns
    sieve [] = []

candidatesBetween :: Integral a => a -> a -> [a]
candidatesBetween x y = let x' = if odd x then x else x + 1 in [x', x' + 2 .. y]

primesFromTo :: Integral a => a -> a -> [a]
primesFromTo x y
    | x < 2 = primesTo y
    | otherwise = snd . sieveWith $ (primes, candidates) where
        primes = tail . primesTo . intSqrt $ y
        candidates = candidatesBetween x y
        sieveWith (a : as, bs' <at> (b : bs)) = sieveWith (as, bs' `minus` multiplies a b) where
        sieveWith ([], bs) = ([], bs)
        multiplies a b = let b' = b + ((-b) `mod` a) in [b', b' + 2 * a .. y]

primesFromTo' [x, y] = primesFromTo x y

main :: IO ()
main = do
    count <- fmap read getLine
    inputLines <- fmap (take count . lines) getContents
    let answers = map (primesFromTo' . map read . words) inputLines
    putStr . unlines . map (unlines . map show) $ answers

=== Origin ===

=== New (./main < data1.txt  4.76s user 0.15s system 99% cpu 4.917 total) ===
{-# OPTIONS_GHC -O2 #-}

import Data.List
import System.IO

minus (x:xs) (y:ys) = case (compare x y) of 
           LT -> x : minus  xs  (y:ys)
           EQ ->     minus  xs     ys 
           GT ->     minus (x:xs)  ys
minus  xs     _     = xs

intSqrt :: Integral a => a -> a
intSqrt = floor . sqrt . fromIntegral

primesTo :: Integral a => a -> [a]
primesTo x = 2 : sieve [3, 5 .. x] where
    sieve ns <at> (n : rs)
        | n <= intSqrt x    = n : sieve (rs `minus` [n * n, n * (n + 2) .. x])
        | otherwise         = ns
    sieve [] = []

candidatesBetween :: Integral a => a -> a -> [a]
candidatesBetween x y = let x' = if odd x then x else x + 1 in [x', x' + 2 .. y]

primesFromTo :: Integral a => a -> a -> [a]
primesFromTo x y
    | x < 2 = primesTo y
    | otherwise = sieveWith primes candidates where
        primes = tail . primesTo . intSqrt $ y
        candidates = candidatesBetween x y
        -- sieve a list of candidates with sieving primes
        -- foldr version: ./main < data1.txt  4.76s user 0.15s system 99% cpu 4.917 total
        sieveWith ps' <at> (p : ps) cs' <at> (c : cs) = foldr (\a b -> b `minus` (multiplies a c)) cs' ps'
        sieveWith [] cs = cs
        multiplies a b = let b' = b + ((-b) `mod` a) in [b', b' + 2 * a .. y]

primesFromTo' [x, y] = primesFromTo x y

main :: IO ()
main = do
    count <- fmap read getLine
    inputLines <- fmap (take count . lines) getContents
    let answers = map (primesFromTo' . map read . words) inputLines
    putStr . unlines . map (unlines . map show) $ answers

=== New ===

Best regards,
Zhi-Qiang Lei

Chaddaï Fouché | 2 Feb 22:36
Picon
Gravatar

Re: Is foldr slow?

On Thu, Feb 2, 2012 at 5:16 PM, Zhi-Qiang Lei <zhiqiang.lei <at> gmail.com> wrote:
> Hi,
>
> When I refactor my Segmented Seive of Eratosthenes, I'm puzzled by the
> performance of "foldr".
> Here is my original code. I realized that "sieveWith"(Integral a => ([a],
> [a]) -> ([a], [a]), it takes a tuple with sieving primes and prime
> candidates, and remove all multiplies of sieving primes in candidates, at
> last return a tuple with blank sieving primes and a pure primes list) in
> "primesFromTo" is not much readable and can be replaced by "foldr".
>

let go a b = b `minus` (multiplies a c)
foldr go cs' (p:p':ps) ==> foldr go cs' (p':ps) `minus` multiplies p c
==> (minus needs his first argument to start removing stuff) (foldr go
cs' ps `minus` multiplies p' c) `minus` multiplies p c
And so on and so forth...
In other words, contrary to your first version, this function must
develop the entire list before making its first suppression...

Your version rather correspond to a foldl (be careful of strictness,
using foldl it's pretty easy to get big thunks).

Foldr is very useful for functions that are lazy in their second
argument like (||) , (&&),  (:) or others but if the function is
strict in its second argument like yours (strict in b)...

--

-- 
Jedaï

_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://www.haskell.org/mailman/listinfo/beginners
Thomas Engel | 3 Feb 19:43
Picon

(no subject)


Thomas Engel | 3 Feb 19:55
Picon

nested guards

Hello,

I'm new to haskell. I want to write a function for a s-curve acceleration in haskell.
A solution in VBA is already working.

Are there nested guards in haskell available or how can I rewrite this function?

The function should calculate the acceleration for a given distance, max acceleration, velocity, jerk at
time since start

acc_skurve::Float->Float->Float->Float->Float->Float
acc_skurve str acc v jerk taktuell
 | str <= str2jerk                  |taktuell <= (0.5 * str / jerk)**(1/3::Float)    = jerk * taktuell
                                    |taktuell <= (4 * str / jerk)**(1/3::Float)      = jerk**(2/3::Float) * 2**(2/3::Float) * str**(1/3::Float)
- jerk * taktuell
                                    |taktuell <= (27/2 * str / jerk)**(1/3::Float)   = - jerk * taktuell + 2**(2/3::Float) * str**(1/3::Float) * jerk**(2/3::Float)
                                    |taktuell <= (32 * str / jerk)**(1/3::Float)     = -2 * 2**(2/3::Float) * str**(1/3::Float) *
jerk**(2/3::Float) + jerk * taktuell
 | str > str2jerk && str < str2acc  |taktuell <= acc / jerk                                                                     = jerk * taktuell                                                                   
                                    |taktuell <= - acc / 2 / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))     = acc                                                                               
                                    |taktuell <=  acc / 2 / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))      = acc / 2 - jerk * taktuell +
sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))      
                                    |taktuell <=  3 * acc / 2 / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))  = acc / 2 - jerk * taktuell +
sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))  
                                    |taktuell <=  sqrt(acc^3 + 4 * str * jerk^2) / (sqrt(acc * jerk))                           = - acc                                                                                                  
                                    |taktuell <=  acc / jerk + sqrt(acc^3 + 4 * str * jerk^2) / (sqrt(acc * jerk))              = - acc + jerk * taktuell -
sqrt(acc^3 + 4 * str * jerk^2) / sqrt(acc)                      
 | str >= str2acc                   |taktuell <= acc / jerk                 = jerk * taktuell                                                                                                                   
                                    |taktuell <= v / acc                    = acc                                                      
                                    |taktuell <= acc / jerk + v / acc       = acc - jerk * taktuell + v * jerk / acc                   
                                    |taktuell <= str / v                    = 0                                                        
                                    |taktuell <= str / v + acc / jerk       = jerk * str / v - jerk * taktuell                         
                                    |taktuell <= str / v + v / acc          = - acc                                                    
                                    |taktuell <= str / v + acc / jerk + v / acc = -(str / v + acc / jerk + v / acc - taktuell) * jerk  
   where str2jerk = 2 * acc^2 / jerk^2
         str2acc  = acc^2 * v + v^2 * jerk / (jerk * acc)

best regards
Thomas

David Frey | 3 Feb 21:16
Picon
Favicon

Re: nested guards

http://www.haskell.org/haskellwiki/Case

That link shows how to write a select function that offers 
functionality similar to a switch statement in C.  Then you could use 
guards for the top-level switching and the select function for the 
second level.

On Fri, 3 Feb 2012 19:55:03 +0100, Thomas Engel wrote:
> Hello,
>
> I'm new to haskell. I want to write a function for a s-curve
> acceleration in haskell.
> A solution in VBA is already working.
>
> Are there nested guards in haskell available or how can I rewrite
> this function?
>
> The function should calculate the acceleration for a given distance,
> max acceleration, velocity, jerk at time since start
>
> acc_skurve::Float->Float->Float->Float->Float->Float
> acc_skurve str acc v jerk taktuell
>  | str <= str2jerk                  |taktuell <= (0.5 * str /
> jerk)**(1/3::Float)    = jerk * taktuell
>                                     |taktuell <= (4 * str /
> jerk)**(1/3::Float)      = jerk**(2/3::Float) * 2**(2/3::Float) *
> str**(1/3::Float) - jerk * taktuell
>                                     |taktuell <= (27/2 * str /
> jerk)**(1/3::Float)   = - jerk * taktuell + 2**(2/3::Float) *
> str**(1/3::Float) * jerk**(2/3::Float)
>                                     |taktuell <= (32 * str /
> jerk)**(1/3::Float)     = -2 * 2**(2/3::Float) * str**(1/3::Float) *
> jerk**(2/3::Float) + jerk * taktuell
>  | str > str2jerk && str < str2acc  |taktuell <= acc / jerk
>                                                          = jerk *
> taktuell
>
>                                     |taktuell <= - acc / 2 / jerk +
> sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))     = acc
>
>
>                                     |taktuell <=  acc / 2 / jerk +
> sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))      = acc / 
> 2
> - jerk * taktuell + sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))
>
>                                     |taktuell <=  3 * acc / 2 / jerk
> + sqrt(acc^3 + 4 * str * jerk^2) / (2 * jerk * sqrt(acc))  = acc / 2 
> -
> jerk * taktuell + sqrt(acc^3 + 4 * str * jerk^2) / (2 * sqrt(acc))
>                                     |taktuell <=  sqrt(acc^3 + 4 *
> str * jerk^2) / (sqrt(acc * jerk))                           = - acc
>
>
>                                     |taktuell <=  acc / jerk +
> sqrt(acc^3 + 4 * str * jerk^2) / (sqrt(acc * jerk))              = -
> acc + jerk * taktuell - sqrt(acc^3 + 4 * str * jerk^2) / sqrt(acc)
>
>  | str >= str2acc                   |taktuell <= acc / jerk
>      = jerk * taktuell
>
>                                     |taktuell <= v / acc
>      = acc
>                                     |taktuell <= acc / jerk + v / acc
>      = acc - jerk * taktuell + v * jerk / acc
>                                     |taktuell <= str / v
>      = 0
>                                     |taktuell <= str / v + acc / jerk
>      = jerk * str / v - jerk * taktuell
>                                     |taktuell <= str / v + v / acc
>      = - acc
>                                     |taktuell <= str / v + acc / jerk
> + v / acc = -(str / v + acc / jerk + v / acc - taktuell) * jerk
>    where str2jerk = 2 * acc^2 / jerk^2
>          str2acc  = acc^2 * v + v^2 * jerk / (jerk * acc)
>
>
> best regards
> Thomas
>
> _______________________________________________
> Beginners mailing list
> Beginners <at> haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

Stephen Tetley | 3 Feb 23:30
Picon

Re: nested guards

On 3 February 2012 20:16, David Frey <dpfrey <at> shaw.ca> wrote:
> http://www.haskell.org/haskellwiki/Case
>
> That link shows how to write a select function that offers functionality
> similar to a switch statement in C.  Then you could use guards for the
> top-level switching and the select function for the second level.

Yikes - that idiom is rather horrible, vis packing cases into a list
so they can be consumed by a function.

To solve the problem, I'd seek a more "mathy" description of the
algorithm i.e. one that doesn't use conditionals so heavily and work
from that rather than translate existing code.

anyzhen | 4 Feb 11:36
Favicon

How memorize intermediate computation value[my brain is so hurt]?

there have a lot of situation we need memorize intermediate computation value. 
and use in further.
like this, compute nth fib question.
So,how memorize it?

i have an ugly solution.it used HashTable for memorization.

fib n table
 | n==1 =1
 | n==2 =1
 | otherwise =
  case lookup table of
    Just v   ->(v,table)
    Nothing ->let (v,table') = fib (n-1) table in
                   let ( v',table'')= v + fib(n-2) table' in
                   (v',table'')

i am an beginner come from imperative programming language.
so fib memorize version program hurt my brain ... particular in Nothing branches.
so do you have some good idea


Gmane