barnameh_riziye_ealani (3)

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






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

امتیاز

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

نقد و بررسی ها

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

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

Guards

اسلاید 1: Guards1Guards

اسلاید 2: Guards2Let’s test this function.Main> maxi 3 23Here is a trace of the function: n mmaxi 3 2Guards or conditions are used to express various cases in the definition of a function.Example:maxi :: Int -> Int -> Int maxi n m | n >= m = n | otherwise = m?? 3 > 2 = True= 3maxi 2 5?? 2 >= 5 = False?? Otherwise = True= 5

اسلاید 3: Guards3function_name p1 p2 … pn | g1 = e1 | g2 = e2 … | otherwise = eThe general form of function definitions using guards:

اسلاید 4: Guards4Example:maxiOf3 :: Int -> Int -> Int -> IntmaxiOf3 m n p | m >= n && m >=p = m | n >= p = n | otherwise = pIf m is the maximum then the first guard will succeed and the result will be m. If the first guard fails then either n or p should be the maximum and this is what the second guard is checking. If the second guard succeeds then the result will be n. Otherwise, if both (first and second) guards fail then the last guard will cause p to be returned as maximum of the three arguments.

اسلاید 5: Guards5Here is a trace of the function: m n pmaxiOf3 9 5 4?? 9 >= 5 && 5 >= 4 = True && True = True= 9maxiOf3 1 2 5?? 1 >= 2 && 2 >= 5 = False && False = False ?? 2 >= 5 = False?? otherwise = True=5Let’s test maxiOf3.Main> maxiOf3 9 5 49maxiOf3 m n p | m >= n && n >=p = m | n >= p = n | otherwise = p

اسلاید 6: Guards6allEqual :: Int -> Int -> Int -> Bool allEqual m n p = (n = = m) && (n = = p) m n pallEqual 2 3 4=(3 = = 2) && (3 = = 4)=False && False=False m n pallEqual (maxi 1 5) 5 (maxi 4 2)= (5 = = (maxi 1 5)) && (5 = = (maxi 4 2)) ?? 1 >= 5 = False ?? otherwise = True= (5 = = 5) && (5 = = (maxi 4 2)) ?? 4 >= 2 = True= (5 = = 5) && (5 = = 4)= True && False= FalseAnother Example:

اسلاید 7: Guards7Error Messages

اسلاید 8: Guards8We will first use Notepad to create a file containing the scriptWe will then use Hugs to interpret this script and find the errorsWe will use Notepad again to edit the file and correct the errorsWe will also test our functions by evaluating some expressions The script on the next slide contains errors

اسلاید 9: Guards9add3 :: Int -> Int -> Int -> Intadd3 n m p = n + m + psig :: Int -> Intsig a_number | a_number < 0 = -1 | a_mumber == 0 = 0 | otherwise = 1 abs :: Int -> Intabs x | x < 0 = x * -1 | otherwise = xanswer :: Intanswer = 42

اسلاید 10: Guards10__ __ __ __ ____ ___ _________________________________________|| || || || || || ||__ Hugs 98: Based on the Haskell 98 standard||___|| ||__|| ||__|| __|| Copyright (c) 1994-2001||---|| ___|| World Wide Web: http://haskell.org/hugs|| || Report bugs to: hugs-bugs@haskell.org|| || Version: December 2001 _________________________________________Hugs mode: Restart with command line option +98 for Haskell 98 modeReading file C:Program FilesHugs98libPrelude.hs:Hugs session for:C:Program FilesHugs98libPrelude.hsType :? for helpPrelude>

اسلاید 11: Guards11Prelude> :l d:haskellsmall.hsReading file d:haskellsmall.hs:ERROR d:haskellsmall.hs:12 - Definition of variable abs clashes with importPrelude>The problem here is that abs is a built-in function. One way of solving this problem is to use a different name for our function. We will now edit the file and fix the error.Prelude> :eThis command ( :e ) tells Hugs to edit the last module.

اسلاید 12: Guards12Reading file d:haskellsmall.hs:Dependency analysisERROR d:haskellsmall.hs:7 - Undefined variable a_mumberThere is an error here to be fixed and we do that using the :e command.Prelude> :eReading file d:haskellsmall.hs:Hugs session for:C:Program FilesHugs98libPrelude.hsd:haskellsmall.hsMain>We should now be able to use these functions in our expressions.

20,000 تومان

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

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

در صورت نیاز با شماره 09353405883 در واتساپ، ایتا و روبیکا تماس بگیرید.

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