Clam Squires resistant to hearing

Source: Internet
Author: User

--Problem (*) Find the last element of a list.--(Note, the Lisp transcription of this problem is incorrect.) --Example in haskell:--prelude> mylast [1,2,3,4]--4--prelude> mylast [' x ', ' y ', ' z ']--' z ' module Main wheremain::i  O () main = putStrLn "Hello World" Mylast:: [a]->amylast [] = error "Error" Mylast [x] = Xmylast (_:xs) = Mylast Xsmylast ' :: [A]-amylast ' = Head.reversemylast ':: [A]--amylast ' xs = xs!! (length Xs-1)--2 problem 2--(*) Find the last and one element of a list.--(Note that the Lisp transcription of this PR Oblem is incorrect.) --Example in haskell:--prelude> mybutlast [1,2,3,4]--3--prelude> mybutlast [' A ' ... ' Z ']--' y ' mybutlast::[a]-amybutlast [] = error "Error" Mybutlast [x] = Error "error" Mybutlast (x:xs) = if length X  s = = 1 then x else mybutlast xsmybutlast ':: [a]->amybutlast ' = Last.initmybutlast ':: [a]->amybutlast ' [x,_] = Xmybutlast "(_:xs) = Mybutlast ' xs--3 problem 3--(*) Find the K ' th element of a list. The first element in the list was number 1.--example:--* (Element-at ' (a b c D e) 3)--c--Example in haskell:--prelude& Gt ElementAt [2--] 2--prelude> elementat "Haskell" 5--' E ' elementat:: [A]->int->aelementat (x:_) 1 = Xel Ementat (_:xs) n = elementat xs (n-1) ElementAt _ _ = Error "Error" ElementAt ':: [A]->int->aelementat ' (x:_) 1 = Xele Mentat ' [] _ = Error "Error" ElementAt ' (_:xs) n = if N<1 then error "error" Else ElementAt ' xs (n-1)--4 proble M 4--(*) Find the number of elements of a list.--Example in haskell:--prelude> mylength [123, 456, 789]--3--Prelud E> mylength "Hello, world!" --13myLength:: [a]->intmylength [] = 0myLength (_:xs) = 1+mylength xsmylength ':: [a], intmylength ' = Sum. Map (\_->1)--5 Problem 5--(*) Reverse a list.--Example in haskell:--prelude> myreverse "A man, a plan, a canal, panama! " --"!amanap, Lanac A, Nalp A, nam a"--prelude> Myreverse [1,2,3,4]--[4,3,2,1]myreverse]:: [A]->[a]myreverse [] = []myreverse (x:xs) = myreverse xs + + + [x] 

Clam Squires resistant to hearing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.