Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  (no subject) (Thomas Engel)
   2.  nested guards (Thomas Engel)
   3. Re:  nested guards (David Frey)
   4. Re:  nested guards (Stephen Tetley)
   5.  How memorize intermediate computation value[my   brain is so
      hurt]? ( anyzhen )
   6. Re:  How memorize intermediate computation value[my brain is
      so hurt]? (Benjamin Edwards)
   7.  yet another monad question (Ovidiu Deac)


----------------------------------------------------------------------

Message: 1
Date: Fri, 3 Feb 2012 19:43:35 +0100
From: Thomas Engel <thomas.eng...@gmx.net>
Subject: [Haskell-beginners] (no subject)
To: beginners@haskell.org
Message-ID: <20120203184335.GA3249@siduxbox>
Content-Type: text/plain; charset=us-ascii




------------------------------

Message: 2
Date: Fri, 3 Feb 2012 19:55:03 +0100
From: Thomas Engel <thomas.eng...@gmx.net>
Subject: [Haskell-beginners] nested guards
To: beginners@haskell.org
Message-ID: <20120203185503.GA3284@siduxbox>
Content-Type: text/plain; charset=us-ascii

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



------------------------------

Message: 3
Date: Fri, 03 Feb 2012 12:16:45 -0800
From: David Frey <dpf...@shaw.ca>
Subject: Re: [Haskell-beginners] nested guards
To: <beginners@haskell.org>
Message-ID: <a59b5c961255ae4154c9c1785c7d4...@dpfrey.dyndns.org>
Content-Type: text/plain; charset=UTF-8; format=flowed

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




------------------------------

Message: 4
Date: Fri, 3 Feb 2012 22:30:58 +0000
From: Stephen Tetley <stephen.tet...@gmail.com>
Subject: Re: [Haskell-beginners] nested guards
Cc: beginners@haskell.org
Message-ID:
        <CAB2TPRBbAfiuZ5ggJiMWkCPmzhker5p1eTK-qrA4BfFy5U=p...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On 3 February 2012 20:16, David Frey <dpf...@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.



------------------------------

Message: 5
Date: Sat, 4 Feb 2012 18:36:28 +0800
From: " anyzhen " <jiangzhe...@qq.com>
Subject: [Haskell-beginners] How memorize intermediate computation
        value[my        brain is so hurt]?
To: " Beginners " <beginners@haskell.org>
Message-ID: <tencent_4764cd8a6aaecf4342e5c...@qq.com>
Content-Type: text/plain; charset="iso-8859-1"

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120204/7e3146e5/attachment-0001.htm>

------------------------------

Message: 6
Date: Sat, 4 Feb 2012 10:47:15 +0000
From: Benjamin Edwards <edwards.b...@gmail.com>
Subject: Re: [Haskell-beginners] How memorize intermediate computation
        value[my brain is so hurt]?
To: anyzhen <jiangzhe...@qq.com>
Cc: Beginners <beginners@haskell.org>
Message-ID:
        <CAN6k4ngoGH--Ww-b9hrhRFkaYdOcHSoW63pUC=svv5xntgf...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

This might help :)

http://www.kennknowles.com/blog/2008/05/10/debugging-with-open-recursion-mixins/

On 4 February 2012 10:36, anyzhen <jiangzhe...@qq.com> wrote:
> 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
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



------------------------------

Message: 7
Date: Sat, 4 Feb 2012 12:49:50 +0200
From: Ovidiu Deac <ovidiud...@gmail.com>
Subject: [Haskell-beginners] yet another monad question
To: beginners <beginners@haskell.org>
Message-ID:
        <cakvse7ud_2adkfpg9zhjows9j7g-vp5jxgrohwqbvezhezx...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I have the following code which works fine:

type File = (String, String) --name and content

readDir :: String -> IO [File]
readDir dir = findRegularFiles dir >>= readFiles
  where
    findRegularFiles = find always (fileType ==? RegularFile)
    readFiles paths = mapM readFile paths >>= return.zip paths

...and I would like to write the function readDir like this:
readDir :: String -> IO [File]
readDir = findRegularFiles >>= readFiles
  where ...

...but I get the error:
grep.hs:46:32:
    Couldn't match expected type `IO [FilePath]'
                with actual type `[FilePath]'
    Expected type: IO [FilePath] -> String -> IO [File]
      Actual type: [FilePath] -> IO [File]
    In the second argument of `(>>=)', namely `readFiles'
    In the expression: findRegularFiles >>= readFiles

Can somebody please explain it?

It's not a big deal. I can keep the old version which works fine. My only
problem is that I thought I understood the monads better but apparently I
don't :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120204/1778a4db/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 44, Issue 4
****************************************

Reply via email to