An warware: boolean

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.

Shafi posts:

Leave a Comment