An warware: sami kirga abu a jeri

Tabbas, bari mu nutse a ciki.

Shirye-shiryen yana cike da damuwa da yawa kuma ษ—ayansu yana koyan yadda ake aiki da lissafin. **Jerisin *** a cikin Haskell tsarin bayanai ne na kamanni wanda zai iya adana abubuwa da yawa iri ษ—aya, yana sa su dace don magance matsaloli iri-iri. A yau, za mu tattauna aiki mai sauฦ™i amma mai amfani akan lissafin - ฦ™ididdige ฦ™ididdiga na abu.

A cikin **Haskell**, za mu yi amfani da wasu ingantattun ayyukan wannan kyakkyawan kuma ingantaccen yaren shirye-shirye.

import Data.List (genericLength)
itemCount :: Eq a => a -> [a] -> Int
itemCount a = fromIntegral . genericLength . filter (== a)

Magani Dalla-dalla

Snippet ษ—in lambar da ke sama yana amfani da haษ—in kayan aikin Haskell, wato GenericLength, tace, da ma'aikacin daidaito. Aikin 'itemCount' yana ฦ™ididdige adadin lokutan abu ya faru a jeri.

Aikin 'itemCount' yana ษ—aukar sigogi biyu: 'a', abin da za a nema da jerin abubuwan ''[a]'. Sa'an nan aikin ya shafi tacewa wanda zai samar da sabon jeri wanda ya ฦ™unshi abubuwa kawai waษ—anda keษ“aษ“ษ“iyar '== a' gaskiya ce. Ana biye da shi ta hanyar amfani da GenericLength, mafi girman sigar aikin tsayi, wanda ke auna tsawon jerin don samun ฦ™idayar wani abu.

Ga jerin kisa:

1. Ana duba lissafin kuma ana fitar da duk abubuwan da suka shafi 'a' ta amfani da tacewa.
2. Ana ฦ™ididdige waษ—annan lokuta ta amfani da tsayin daka.

Game da Laburaren Haskell da Ayyuka

Maganin yana amfani da daidaitattun ษ—akunan karatu na Haskell da ayyuka ** kamar tsayin tsayi da tacewa.

Aikin 'GonericLength' wani bangare ne na laburare na Data.List a Haskell. Yana da ฦ™arin juzu'i na aikin tsawon lokaci na yau da kullun saboda yana iya ษ—aukar jerin kowane nau'i kuma ya dawo da lamba wanda ke wakiltar jimillar abubuwan da ke cikin jeri.

Aikin 'tace', a gefe guda, yana cikin gabatarwa. Yana da aiki mafi girma wanda ke ษ—aukar predicate da jeri kuma ya dawo da jerin abubuwan da ke gamsar da predicate.

Amfani da 'Eq' a Haskell

A cikin snippet code, za ku ga cewa mun saka Eq a cikin sa hannun aikin. 'Eq' nau'in nau'in nau'i ne a Haskell. Yana bayyana ayyukan daidaito gami da `==` da `/=`, duk nau'ikan da ke son yin amfani da gwajin daidaito yakamata su sami misalin wannan ajin.

A ฦ™arshe, haษ“akawa da ladabi suna cikin zuciyar lambar ฦ™arfi, kama da salon. ฦ˜aฦ™ฦ™arfan kamanceceniya tsakanin, a ce, harsuna masu aiki kamar Haskell, da kuma babban salon su ne cewa dukansu suna ba mu kayan aiki da ฦ™a'idodi don bayyana kanmu, da kuma cewa harsunan da muke amfani da su suna tsara sakamakon ฦ™arshe.

A kan wannan bayanin, ci gaba da bincike, ci gaba da yin codeing, kuma ku ci gaba da jujjuya kanku tare da salo mai ban sha'awa da na musamman na lambar, mai kama da mai nuna kan titin jirgin sama.

Shafi posts:

Leave a Comment