An warware: ƙari na lambobi biyu

A cikin duniyar zamani, manufar ƙari yana kusan zama a ko'ina kamar masana'anta na gaskiyar kanta. A cikin fagage da yawa na ƙoƙarin ɗan adam, aikin lissafin yana samun aikace-aikace marasa ƙima, daga ainihin ilimin lissafi da ake koyarwa a makarantun firamare zuwa ƙididdige ƙididdiga masu mahimmanci zuwa tsarin fasaha na ci gaba. Haskell, yaren shirye-shirye ne kawai mai aiki, yana sauƙaƙa aiwatar da ƙari sosai tare da ƙayyadaddun ƙayyadaddun ƙayyadaddun ƙayyadaddun bayanai.

Batun yin ƙari a cikin Haskell na iya zama kamar madaidaici, ko da maras muhimmanci, amma a ƙarƙashin ƙasa akwai la'akari da mahimmanci da yawa. Mu shiga ciki.

Ayyuka a Haskell da Aikin Farko (+)

Haskell, kamar kowane yaren shirye-shirye, yana ba da daidaitattun ayyukan lissafi kamar ƙari, ragi, ninkawa, da rarrabawa. A cikin yanayinmu, muna sha'awar mafi sauƙi daga cikin waɗannan: Ƙarin aiki. Ana samun wannan ta amfani da aikin farko (+) a cikin Haskell.

Ana yin aikin ƙari tare da mai aiki (+). Furcin (x + y) yana ƙara x da y. Yi la'akari da wannan sauƙi Haskell code:

x = 5
y = 10
sum = x + y

Anan, muna da lamba biyu, 5 da 10, waɗanda aka sanya su zuwa masu canji x da y bi da bi. Sa'an nan kuma mu ƙara waɗannan lambobi biyu tare da x + y da kuma adana sakamakon a jimlar. Darajar jimlar za ta zama 15.

Bayanin mataki-mataki na Code

A faɗaɗa, lambar tana aiki a matakai masu hankali uku. Bari mu rushe shi don kyakkyawar fahimta:

  • Layin farko, 'x = 5', yana bayyana mabambanta x kuma ya sanya masa ƙimar 5.
  • Layi na biyu yana yin irin wannan aiki. Yana sanya darajar 10 ga mai canzawa y.
  • Layi na uku, 'sum = x + y', shine inda aikin kari ke faruwa. Mai aiki da (+) yana ƙara ƙimar da aka adana a x da y, kuma ana sanya sakamakon zuwa jimlar mai canzawa.

Sauƙi da taƙaitaccen bayanin Haskell yana haskakawa sosai a nan, yayin da gabaɗayan aikin ƙari yana cikin layi ɗaya na lamba – 'sum = x + y'.

Laburaren Lissafi a Haskell

Yayin da aikin (+) babban aiki ne wanda kunshin tushe ya samar a cikin Haskell, akwai ɗakunan karatu na lissafi da yawa waɗanda ke ba da ƙarin fa'idodi masu rikitarwa. Dakunan karatu kamar Num, Real, Integral, Fractional, da Floating waɗanda ke samar da nau'ikan nau'ikan lambobi na Haskell kuma suna iya tallafawa ayyuka da yawa gami da, amma ba'a iyakance ga ƙari ba. Daga ɗimbin ƙididdige ƙididdiga na ci gaba, Haskell na iya sarrafa shi duka ba tare da ɓata lokaci ba tare da taimakon waɗannan ɗakunan karatu masu ƙarfi.

Fahimtar wannan ƙari, a matsayin mai sauƙi kamar yadda ake gani, ya zama ginshiƙin ƙididdiga masu rikitarwa. Koyon yadda ake sarrafa wannan aiki a Haskell zai buɗe hanya don fahimtar ƙarin hadaddun ayyukan lissafi a Haskell. Yayin da mutum ya zurfafa cikin shirye-shiryen Haskell, waɗannan abubuwan yau da kullun za su riƙe mahimmanci.

Hanyar da za a ɗauka ita ce, ko da yaren, manufar ƙari yana kiyaye mahimmancinsa kuma yana ci gaba da zama muhimmin tubalin ginin duniya na shirye-shirye, lissafi, da kuma bayansa.

Shafi posts:

Leave a Comment