Send Beginners mailing list submissions to
        [email protected]

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
        [email protected]

You can reach the person managing the list at
        [email protected]

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


Today's Topics:

   1. Re:  The application of application (Kim-Ee Yeoh)
   2.  my fist program (Ezequiel Hernan Di Giorgi)
   3. Re:  my fist program (Reto Habl?tzel)


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

Message: 1
Date: Sun, 2 Dec 2012 18:07:04 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] The application of application
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <CAPY+ZdQ+cTuq5x-T-qG2944z=wb6jgm+qzaudzpxm-sqbjr...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Sun, Dec 2, 2012 at 5:31 AM, Christopher Howard <
[email protected]> wrote:
> But I have a compulsive hatred of duplication.

And thus haskell code golfing is born! Actually that's not always true. The
motivation is sometimes compellingly noble. E.g. we want a faithfully
compact translation of (English!)

"Given some number compute both its sine and cosine, both scaled by
velocityC."

into

import Control.Arrow( (***), (&&&) )
import Control.Monad( join )

f = join (***) (velocityC*) . (sin &&& cos)

Unfamiliarity with symbol-rich combinators has been known to exact
cognitive pain, leading to unfortunate comparisons with Perl. Evidently,
the story isn't always driven by sadism.

Credits: I asked a similar question years ago [1] and got a heap of useful
replies. Special mention to Robert Vollmert and Luke Palmer for help
arriving at the above version.

[1] http://www.haskell.org/pipermail/haskell-cafe/2009-February/056195.html

-- Kim-Ee


On Sun, Dec 2, 2012 at 5:31 AM, Christopher Howard <
[email protected]> wrote:

> Can application of an expression (to a function) be treated like a
> function itself? In my specific case, I started with this expression:
>
> code:
> --------
> (cos b * velocityC, sin b * velocityC)
> --------
>
> But I have a compulsive hatred of duplication. I happened to have this
> function handy called appPair:
>
> code:
> -------
> appPair f (a, b) = (f a, f b)
>
> appPair (* velocityC) (cos b, sin b)
> -------
>
> Better, but the b identifier is still duplicated. Is there some way I
> could have...
>
> code:
> --------
> appPair (?) (cos, sin)
> --------
>
> ...shifting the application of b into the (* velocityC) expression,
> without modifying my appPair function?
>
> --
> frigidcode.com
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121202/cd9bfd61/attachment-0001.htm>

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

Message: 2
Date: Sun, 2 Dec 2012 09:43:46 -0300
From: Ezequiel Hernan Di Giorgi <[email protected]>
Subject: [Haskell-beginners] my fist program
To: [email protected]
Message-ID:
        <cahrx9sxlhojiupbfys_clzdo5bbzd1rwrhanbbfp-gywxg1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hola! Hallo!
I made my first program to understand lists and something about datat
types. I have some question about the following code...
*

import* Data.List
*data* Student =      Student { id     :: Int,               nombre ::
String             } *deriving* (*Show*, *Eq*)
main :: IO ()main = *do* putStrLn "---\nStudent Magnament
Program\n---"          loop [] ashow :: [Student] -> IO ()ashow []
= putStrLn "Empty list"ashow [x]   = putStrLn $ show xashow (x:xs)=
*do* putStrLn $ show x                 ashow xs aadd :: [Student] ->
IO ()aadd xs = *do* putStrLn "Enter the id"             id <- getLine
           putStrLn "Enter name"             name <- getLine
  loop $ (Student (read id) (read name) ) : xs             aremove ::
[Student] -> IO ()aremove xs = *do* putStrLn "Enter the id"
    id <- getLine                putStrLn "Enter name"
name <- getLine                loop $ delete (Student (read id) (read
name) ) xs              loop :: [Student] -> IO ()loop xs = *do*
putStr $ "\n-------\nSelect an option\n"                        ++ "1)
Add student\n"                        ++ "2) Remove student\n"
               ++ "3) Show all students\n"                        ++
"4) Exit\n"                        ++ "\t Your option: "
option <- getLine             putStrLn "\n------"             *case*
read option *of*                  1 -> aadd xs                  2 ->
aremove xs                  3 -> *do* ashow xs
 loop xs                  4 -> putStrLn "God bye!"


My question are:

   - When i ask for the data fof a student i repeat the code, cause i have
   to use fuctions using IO (), cuase i have to put something in the
   screen. Therefore i cant have a fuction that only return a Student.
   - loop $ (Student $ read id $ read name), is wrong why?
   - i think that there are best way to achive that i have done. Or is ok
   for a begginer that doesn't know functors or monads.


Sorry for my bad english, i am Argentinean.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121202/d1ec38d7/attachment-0001.htm>

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

Message: 3
Date: Sun, 2 Dec 2012 14:49:15 +0100
From: Reto Habl?tzel <[email protected]>
Subject: Re: [Haskell-beginners] my fist program
To: Ezequiel Hernan Di Giorgi <[email protected]>
Cc: [email protected]
Message-ID:
        <cajzydzg9smcnuzrsr91_sbmm+gnbmp9jdpoqzbbmmo12oa6...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

well you're using the IO Monad all over the place. Instead I suggest using
it only in certain places (like main) and keep the functions pure in
general. One way to improve this might be to start from the inside and
first think about what functions you need and then what the types should
look like. For example you need a function to add a student to the list,
the type of pure function which does that looks like this:
*aadd :: [Student] -> Student -> [Student]*
Then implement this function and think from the outside: Given some user
input, how can I create a student? Take a look at this[1] page.. you'll
find a suggestion on how to improve your *ashow* function there.


*loop $ (Student $ read id $ read name), is wrong why?*
 That operator you are using three times there basically says: "Evaluate
the right thing first", so what you end up with after *read name* has been
evaluated is *read id (read name)*. Once you understand that, you'll also
find that the braces are unnecessary (though not wrong).

If you want to avoid the IO Monad in general then I suggest you "test" your
program with GHCI.

I'm sure you'll also find examples for basic input-dialog haskell programs
in either *Learn You a Haskell[2] for Great Good* or *Real World Haskell*
[3].

1: http://learnyouahaskell.com/types-and-typeclasses
2: http://learnyouahaskell.com/
3: http://book.realworldhaskell.org/

Cheers,
Reto


On Sun, Dec 2, 2012 at 1:43 PM, Ezequiel Hernan Di Giorgi <
[email protected]> wrote:

> Hola! Hallo!
> I made my first program to understand lists and something about datat types. 
> I have some question about the following code...
>
>
> *
>
> import* Data.List
> *data* Student =      Student { id     :: Int,               nombre :: String 
>             } *deriving* (*Show*, *Eq*)
> main :: IO ()main = *do* putStrLn "---\nStudent Magnament Program\n---"       
>    loop [] ashow :: [Student] -> IO ()ashow []    = putStrLn "Empty 
> list"ashow [x]   = putStrLn $ show xashow (x:xs)= *do* putStrLn $ show x      
>            ashow xs aadd :: [Student] -> IO ()aadd xs = *do* putStrLn "Enter 
> the id"             id <- getLine             putStrLn "Enter name"           
>   name <- getLine             loop $ (Student (read id) (read name) ) : xs    
>          aremove :: [Student] -> IO ()aremove xs = *do* putStrLn "Enter the 
> id"                id <- getLine                putStrLn "Enter name"         
>        name <- getLine                loop $ delete (Student (read id) (read 
> name) ) xs              loop :: [Student] -> IO ()loop xs = *do* putStr $ 
> "\n-------\nSelect an option\n"                        ++ "1) Add student\n"  
>                       ++ "2) Remove student\n"                        ++ "3) 
> Show all students\n"                        ++ "4) Exit\n"                    
>     ++ "\t Your option: "             option <- getLine             putStrLn 
> "\n------"             *case* read option *of*                  1 -> aadd xs  
>                 2 -> aremove xs                  3 -> *do* ashow xs           
>                loop xs                  4 -> putStrLn "God bye!"
>
>
> My question are:
>
>    - When i ask for the data fof a student i repeat the code, cause i have
>    to use fuctions using IO (), cuase i have to put something in the
>    screen. Therefore i cant have a fuction that only return a Student.
>    - loop $ (Student $ read id $ read name), is wrong why?
>    - i think that there are best way to achive that i have done. Or is ok
>    for a begginer that doesn't know functors or monads.
>
>
> Sorry for my bad english, i am Argentinean.
>
> Thanks in advance.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20121202/4d81695d/attachment.htm>

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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 54, Issue 3
****************************************

Reply via email to