operatorha_va_tavabeae_barnameh_nevisi

در نمایش آنلاین پاورپوینت، ممکن است بعضی علائم، اعداد و حتی فونت‌ها به خوبی نمایش داده نشود. این مشکل در فایل اصلی پاورپوینت وجود ندارد.




  • جزئیات
  • امتیاز و نظرات
  • متن پاورپوینت

امتیاز

درحال ارسال
امتیاز کاربر [0 رای]

نقد و بررسی ها

هیچ نظری برای این پاورپوینت نوشته نشده است.

اولین کسی باشید که نظری می نویسد “Operators and Functions”

Operators and Functions

اسلاید 1: Operators, Functions and Modules1Operators and Functions

اسلاید 2: Operators, Functions and Modules2infix notation:a + b + is called an operator prefix notation: mod a b mod is called a functionAn operator can be used in expressions just like a function and vice versa. Prelude> 2*48Prelude> (*) 2 48Prelude>div 9 33Prelude> 3 ‘div’ 2ERROR - Improperly terminated character constantPrelude>9 `div` 33Both prefix and infix notations are allowed in Haskell.

اسلاید 3: Operators, Functions and Modules3Example:(<->) :: Int -> Int -> Boola <-> b | mod a b= = 0 = True | otherwise = False Main> 4 <-> 2TrueMain> 4 <-> 3FalseYou may even define your own infix operators in the same way as functions. You may not begin an operator with a “:”.

اسلاید 4: Operators, Functions and Modules4Doing the same is not possible with subtraction as it is not associative. 3 – 2 – 1Left associative: (3 – 2) – 1 = 0right associative: 3 – (2 – 1) = 2Non associative operators are either left or right associative in Haskell.Associativity Addition is associative because the order of its application does not matter. In an expression like 1+2+3 we may write: 1+ ( 2 + 3) or (1 + 2) + 3without effecting the results. That is why we do not use the brackets in such cases.

اسلاید 5: Operators, Functions and Modules5 ^ is right associative and has a binding power of 8 *, / are left associative and have a binding power of 7 +, – are left associative and have a binding power of 6++ is right associative and has a binding power of 5/=, <, <= , >, >= are non-associative and have a binding power of 4Associativity can help in resolving ambiguity in the use of an operator.When more than one operator is involved then the binding power (or infixity) is used to resolve ambiguity. 18 – 4 * 2 = 10 binding power “*”= 7 ; “–” , “+” = 62 ^ 3 ^ 2 = 512 ^ is right associative4 ^ 3 * 2 = 128 The maximum possible binding power is 9You can change the associativity or binding power of an operator.Binding Power

اسلاید 6: Operators, Functions and Modules6infixr binding-power operator infixl binding-power operatorinfix binding-power operatorExamples:infixr 7 <-> infixl 5 <-> We may even do this with backquoted function names.infixr 8 `fact`Setting the associativity and/or binding power of an operator:You can use declarations of the form,

اسلاید 7: Operators, Functions and Modules7fact n + 1means(fact n) + 1.If we wanted it to mean factorial of (n+1) then we would say,fact (n + 1).Negative NumbersBecause minus is used both as the subtraction and negation operators,fact –1 is interpreted as fact minus 1 and not,fact (-1).Use brackets when you are not sure.Binding power of function applications is the highest. So,

اسلاید 8: Operators, Functions and Modules8ERROR - Unresolved overloading*** Type : Num Bool => Bool*** Expression : 24 <-> 3 * 6Adding the proper declaration will solve the problem.(<->) :: Int -> Int -> Boola <-> b | mod a b= = 0 = True | otherwise = Falseinfixr 4 <-> Main> 24 <-> 3*6FalseMain> 24 <-> 3*6

اسلاید 9: Operators, Functions and Modules9Layout

اسلاید 10: Operators, Functions and Modules10What determines where one function ends and the other begins in a Haskell script ? This may be done explicitly by using a semicolon (“;”) at the end of a definition. Using semicolons, you can put more than one definition on a line. answer = 20; done = FalseWe normally do not use semicolons. The layout of Haskell scripts is used to tell where a function ends and another begins.fact n = product [1..n]maxi m n | m > n …The following layout will result in erroradd1 x = x +1 ERROR add1.hs:2 - Syntax error in expression (unexpected `;, possibly due to bad layout)This layout rule is called the offside rule.

اسلاید 11: Operators, Functions and Modules11Modules and Imports

اسلاید 12: Operators, Functions and Modules12module Fact where-- function to find the factorial of a given integerfact :: Integer -> Integerfact n = product [1..n]-- function to find the square of a numbersqu :: Integer -> Integersqu n = n*n{- Function to change the case of a given character -}offset::Intoffset=ord A - ord achangeCase:: Char -> CharchangeCase ch = if (ord ch > 96) then chr(ord ch + offset) else chr (ord ch - offset)

اسلاید 13: Operators, Functions and Modules13Prelude> :l d:haskellcompilerfact.hsReading file d:haskellcompilerfact.hs:Hugs session for:C:Program FilesHugs98libPrelude.hsd:haskellcompilerfact.hsFact>fact 36Fact>fact 424Fact>

اسلاید 14: Operators, Functions and Modules14module test where -- import from module Factimport fact -- function to find the number of combinationscomb :: Integer -> Integer -> Integercomb n r = fact n `div` (fact r * fact (n - r))Prelude> :l d:haskellcompilerfact.hsReading file d:haskellcompilerfact.hs:…Hugs session for:C:Program FilesHugs98libPrelude.hsd:haskellcompilerfact.hsFact> :l d:haskellcompilertest.hsHugs session for:C:Program FilesHugs98libPrelude.hsd:haskellcompilerfact.hsd:haskellcompilertest.hsTest> comb 3 2 result will be 3

34,000 تومان

خرید پاورپوینت توسط کلیه کارت‌های شتاب امکان‌پذیر است و بلافاصله پس از خرید، لینک دانلود پاورپوینت در اختیار شما قرار خواهد گرفت.

در صورت عدم رضایت سفارش برگشت و وجه به حساب شما برگشت داده خواهد شد.

در صورت بروز هر گونه مشکل به شماره 09353405883 در ایتا پیام دهید یا با ای دی poshtibani_ppt_ir در تلگرام ارتباط بگیرید.

افزودن به سبد خرید