Tabbas, a nan ya tafi.
ฦarfin boolean a cikin Haskell yana da ikon ฦirฦirar tunani wanda zai iya bayyana dama da sakamako masu yawa. Suna kafa tushen tsarin sarrafawa da yanke shawara a Haskell.
Fahimtar yadda ake amfani da darajojin Boolean yadda ya kamata na iya haษaka dabaru na lambar ku da ฦarfin shirye-shiryenku na Haskell.
Kyawun Boolean a Haskell
Boolean in Haskell nau'in bayanai ne. Yana da masu gina ฦima guda biyu, Gaskiya da ฦarya, waษanda su ne madaidaicin ma'auni masu wakiltar ฦimar gaskiya guda biyu. Haskell yana amfani da nau'in Bool don algebra na Boolean. Maโanar Boolean ta zama ginshiฦi na ilimin lissafi kuma ana amfani da shi a aikin injiniyan lantarki da kimiyyar kwamfuta. Bayan haka, ana amfani da su don kwatanta masu canji da maganganu.
A cikin Haskell, ma'anar Boolean ta ta'allaka ne akan manyan ayyuka guda uku: AND, KO, kuma BA. A cikin Haskell, ana nuna waษannan a matsayin &&, ||, kuma ba bi da bi ba. Kamar ayyukan lissafi, ayyukan boolean suna bin ฦayyadaddun fifiko da ฦa'idodin haษin kai.
-- The 'AND' operation True && True -- evaluates to True True && False -- evaluates to False False && True -- evaluates to False False && False -- evaluates to False -- The 'OR' operation True || True -- evaluates to True True || False -- evaluates to True False || True -- evaluates to True False || False -- evaluates to False -- The 'NOT' operation not True -- evaluates to False not False -- evaluates to True
Ayyukan Boolean na Haskell
Ayyukan Boolean sune ayyukan da ke ษaukar abubuwan shigar Boolean kuma suna dawo da abubuwan Boolean. Wadannan ayyuka suna aiwatar da hadaddun ayyuka na ma'ana dangane da bukatunmu kuma wani bangare ne na shirye-shirye a Haskell.
Bari mu zurfafa zurfafa cikin Ayyukan Boolean na Haskell:
Harshen shirye-shirye mai ฦarfi Haskell yana da ayyukan ginannen ayyuka waษanda ke ษaukar ฦimar boolean azaman sigogi da fitar da ฦimar boolean gwargwadon ma'anar da aka ayyana su da su. Waษannan ayyuka sun haษa da "da", "ko", da "a'a".
Amfani da waษannan ayyuka za mu iya yin ayyuka masu ma'ana akan lissafin boolean.
and [True, True, False] -- evaluates to False or [True, False, False] -- evaluates to True not True -- evaluates to False
Aikin "da" yana dawowa Gaskiya idan kuma kawai idan duk abubuwan da ke cikin jerin gaskiya ne. Aikin "ko" yana dawowa Gaskiya idan aฦalla kashi ษaya a cikin jerin gaskiya ne. Aikin โbaโ yana jujjuya ฦimar shigarwar boolean, idan gaskiya ne ya zama Karya kuma akasin haka.
Tsarin Yanayi Amfani da Dabarun Boolean
Ku yi imani da shi ko a'a, Boolean yana taka muhimmiyar rawa a cikin tsari na yanayi a cikin coding tare da Haskell. A cikin Haskell, ana amfani da kalmar idan-sai-wani don gabatar da iyawar yanke shawara a cikin shirye-shiryenmu. Ga misalin shirin Haskell ta amfani da ma'anar Boolean don yanke shawarar wace kirtani za a buga dangane da ฦimar lamba:
rajistan lamba :: Int -> String
duba lamba n =
idan n > 10 to "Fiye da goma"
idan kuma n <10 sai "kasa da goma" sai kuma "Goma ne" main = putStrLn(checkNumber 10) -- goma ne [/ code] A cikin shirin da ke sama, checkNumber yana ษaukar lamba a matsayin shigarwa kuma ya danganta da ฦimar lamba. , yana dawo da madaidaicin kirtani. Don yin wannan yanke shawara, yana amfani da juzu'i idan-sai-wani wanda yanayin farko (n> 10 ko n <10) zai zama furci na boolean wanda shirin Haskell ya kimanta zuwa ko dai na gaskiya ko na ฦarya. Maganar dama bayan "to" ana aiwatar da ita idan yanayin gaskiya ne; in ba haka ba, idan yanayin ฦarya ne, ana aiwatar da kalmar nan da nan bayan "wani". Wannan shine ainihin misali na yanke shawara a cikin shirye-shiryen Haskell ta amfani da dabaru na Boolean.