SlideServe
Menu
Préférences
© SlideServe · v2026

Programming Paradigms

edolie avatar
8 diapositives · 287 Views · Jul 23, 2014

Programming Paradigms. CPSC 449 Week 2-1 Prepared by : Mona Hosseinkhani, Arash Afshar Winter 2014. Some Excercises. Load the file FirstScript.hs and evaluate the following expressions: square size let d = double 2 23 - double (3+1) 23 - double 3+1

Programming Paradigms - slide 1
01 / 8Programming Paradigms
1 / 17

Télécharger la présentation

Programming Paradigms
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Programming Paradigms CPSC 449 Week 2-1 Prepared by : Mona Hosseinkhani, ArashAfshar Winter 2014

  2. Some Excercises • Load the file FirstScript.hs and evaluate the following expressions: • square size • let d = double 2 • 23 - double (3+1) • 23 - double 3+1 • Use :type to tell the type of each of the above expressions. • Edit the file FirstScript.hs to include the following definitions • The function should double its input and square the result of that. • The function should square its input and double the result of that.

  3. Integer type and some of its operations • Arithmetic operators • +, *, ^, - ,… • div, mod, abs, negate • Relational Operators • >, >=, <, <=, /=, == • fromInteger :: Integer -> Int • toInteger :: Int -> Integer

  4. Char and String types and some of their operations • fromEnum :: Char -> Int • toEnum :: Int -> Char • putStr :: String -> IO () • putStrLn:: String -> IO () • ++ : concatenates two Strings • show : Converts from a value to a String • Show (2+3) • read : Converts a String to a value • read “True”

  5. Redefining Prelude functions • The “max” function is defined both in the Prelude.hs and Chapter3.hs • Max :: Integer -> Integer -> Integer • Ambiguous occurrence `max’It could refer to either `Chapter3.max’,defined at Chapter3.hs:70:1or `Prelude.max’,imported from `Prelude' at Chapter3.hs 11:8-15 (and originally defined in `GHC.Classes’) • Import Prelude hiding (max)

  6. Syntax • A function definition ends by the first piece of text which lies at the same indentation or to the left of the start of the definition. (offside rule) e.g. mystery x = x * x +x +2 next y =… • Incorrect syntax: • Funny x = x+1 • In Haskell end symbol is ‘;’. Use it when you want to write more than one definition on a single line.

  7. Summary • Installing Haskell platform and downloading the textbook codes. • Fire up GHCi (GHC interactive) and try some examples • GHCi commands and how to use them • Infix notation in Haskell • Testing the programs in Haskell. • Integer type and some of its operations • Char and String types and some of their operations • Redefining Prelude functions. • Syntax

  8. Questions hossem@ucalgary.ca http://www.ucalgary.ca/mhosseinkhani/CPSC449