Tutorial 4 Find the Error

Total Page:16

File Type:pdf, Size:1020Kb

Tutorial 4 Find the Error Tutorial 4 Find the error 1. let rec rotate n l = match n,l with 0,_ -> l |n,x::xs -> rotate (n-1) (xs@x) | _, _ -> failwith "rotate “ Error: This expression has type 'a but an expression was expected of type 'a list The type variable 'a occurs inside 'a list difference between the two funcLons 1. let rec rotate n l = match n,l with 0,_ -> l |n,x::xs -> rotate (n-1) (xs@[x]) | _, _ -> failwith "rotate " • rotate 3 [1;2;3;4;5]= = [4;5;1;2;3] 2. let rec rotate n l = match n,l with 0,_ -> l |n,x::xs -> rotate (n-1) xs@[x] | _, _ -> failwith "rotate " • rotate 3 [1;2;3;4;5]=[4;5;3;2;1] :: VS @ • For each of the following expressions, specify 1. If it is valid or not 2. The result list 3. The length of the result list :: VS @ ①[3] @ [4] ①int list = [3; 4] , length=2 ②3 @ 4 ②Invalid ③[3; 4] @ [] ③int list = [3; 4] , length=2 ④[3; 4] :: [] ④int list list = [[3; 4]] , length=1 ⑤[3] :: 4 ⑤Invalid ⑥3 :: [4] ⑥int list = [3; 4] , length=2 ⑦[] @ [[3]; [4]] ⑦int list list = [[3]; [4]] , length=2 ⑧[] :: [[3]; [4]] ⑧int list list = [[]; [3]; [4]] ,length=3 PracLce funcLon1 • Write a funcLon sum that takes a list and returns another list which sums the first element of the list with the last element and the second element of the list with the second to last element and so on. • Example • Sum [1]=[2] • Sum [1;2;4;7]=[8;6] • Sum [1;2;5]=[6;4] • let rec sum l= match l with • |[]->[] • |[x]->[x+x] • |x::xs-> ( • match List.rev(xs) with • |y::ys -> x+y::sum (List.rev(ys)) • |_ ->failwith "sum” );; PracLce funcLon 2 • A funcLon takes in a sorted list, and removes any duplicates. – As the list is sorted, any duplicates would be next to each other let rec uniq list = • match list with • [] -> [] • | h1 :: [] -> h1 :: [] • | h1 :: h2 :: tail -> if h1 = h2 • then uniq (h2 :: tail) • else h1 :: uniq (h2 :: tail);; WEEK 4 ASSIGNMENTS E1 • Write a funcLon that checks whether an element is a member of a list. • member : 'a -> 'a list -> bool • For example, • member 2 [1; 2; 3] = true • member 7 [1; 2; 3; 4] = false • member 'a' [ ] = false E1 • let rec member x = funcLon • | [] -> false • | h::t -> x == h || member x t;; E2 • Write a funcLon • prefix : 'a list -> 'a list -> bool • which returns true if the first argument is a prefix of the second argument. For example: • prefix [] [1; 2; 3] = true • prefix [1] [1; 2; 3] = true • prefix [1; 3] [1; 2; 3] = false E2 • let rec prefix xs ys = match xs, ys with • | [], _ -> true • | _, [] -> false • | (h::t), (h'::t') -> h == h' && prefix t t';; P • Write a funcLon which returns all the prefixes of a list (as a list of lists). • prefixes : 'a list -> 'a list list • For example • prefixes [1; 2; 3] = [[]; [1]; [1; 2]; [1; 2; 3]] P • let rec prefixes' p = funcLon • | [] -> [p] • | h::xs -> p::prefixes' (p @ [h]) xs;; • let prefixes xs = prefixes' [] xs;; .
Recommended publications
  • UNIX Commands
    UNIX commands ls list the contents of a directory ls -l list the content of a directory with more details mkdir <directory> create the directory <directory> cd <directory> change to the directory <directory> cd .. move back one directory cp <file1> <file2> copy the file <file1> into <file2> mv <file1> <file2> move the file <file1> to <file2> rm <file> remove the file <file> rmdir <directory> delete the directory <directory> man <command> display the manual page for <command> module load netcdf load the netcdf commands to use module load ferret load ferret module load name load the module “name” to use its commands vi <file> read the content of the file <file> vimdiff <file1> <file2> show the differences between files <file1> and <file2> pwd show current directory tar –czvf file.tar.gz file compress one or multiple files into file.tar.gz tar –xzvf file.tar.gz extract the compressed file file.tar.gz ./name execute the executable called name qsub scriptname submits a script to the queuing system qdel # cancel the submitted job number # from the queue qstat show queued jobs qstat –u zName show only your queued jobs Inside vi ESC, then :q! Quit without saving ESC, then :wq Quit with saving ESC, then i Get in insert mode to edit text ESC, then /word Search content for word ESC, then :% Go to end of document ESC, then :0 Go to beginning of document ESC, then :set nu Add line numbers ESC, then :# Go to line number # N.B.: If inside vimdiff, you have 2 files opened, so you need to quit vi twice.
    [Show full text]
  • LATEX for Beginners
    LATEX for Beginners Workbook Edition 5, March 2014 Document Reference: 3722-2014 Preface This is an absolute beginners guide to writing documents in LATEX using TeXworks. It assumes no prior knowledge of LATEX, or any other computing language. This workbook is designed to be used at the `LATEX for Beginners' student iSkills seminar, and also for self-paced study. Its aim is to introduce an absolute beginner to LATEX and teach the basic commands, so that they can create a simple document and find out whether LATEX will be useful to them. If you require this document in an alternative format, such as large print, please email [email protected]. Copyright c IS 2014 Permission is granted to any individual or institution to use, copy or redis- tribute this document whole or in part, so long as it is not sold for profit and provided that the above copyright notice and this permission notice appear in all copies. Where any part of this document is included in another document, due ac- knowledgement is required. i ii Contents 1 Introduction 1 1.1 What is LATEX?..........................1 1.2 Before You Start . .2 2 Document Structure 3 2.1 Essentials . .3 2.2 Troubleshooting . .5 2.3 Creating a Title . .5 2.4 Sections . .6 2.5 Labelling . .7 2.6 Table of Contents . .8 3 Typesetting Text 11 3.1 Font Effects . 11 3.2 Coloured Text . 11 3.3 Font Sizes . 12 3.4 Lists . 13 3.5 Comments & Spacing . 14 3.6 Special Characters . 15 4 Tables 17 4.1 Practical .
    [Show full text]
  • PS TEXT EDIT Reference Manual Is Designed to Give You a Complete Is About Overview of TEDIT
    Information Management Technology Library PS TEXT EDIT™ Reference Manual Abstract This manual describes PS TEXT EDIT, a multi-screen block mode text editor. It provides a complete overview of the product and instructions for using each command. Part Number 058059 Tandem Computers Incorporated Document History Edition Part Number Product Version OS Version Date First Edition 82550 A00 TEDIT B20 GUARDIAN 90 B20 October 1985 (Preliminary) Second Edition 82550 B00 TEDIT B30 GUARDIAN 90 B30 April 1986 Update 1 82242 TEDIT C00 GUARDIAN 90 C00 November 1987 Third Edition 058059 TEDIT C00 GUARDIAN 90 C00 July 1991 Note The second edition of this manual was reformatted in July 1991; no changes were made to the manual’s content at that time. New editions incorporate any updates issued since the previous edition. Copyright All rights reserved. No part of this document may be reproduced in any form, including photocopying or translation to another language, without the prior written consent of Tandem Computers Incorporated. Copyright 1991 Tandem Computers Incorporated. Contents What This Book Is About xvii Who Should Use This Book xvii How to Use This Book xvii Where to Go for More Information xix What’s New in This Update xx Section 1 Introduction to TEDIT What Is PS TEXT EDIT? 1-1 TEDIT Features 1-1 TEDIT Commands 1-2 Using TEDIT Commands 1-3 Terminals and TEDIT 1-3 Starting TEDIT 1-4 Section 2 TEDIT Topics Overview 2-1 Understanding Syntax 2-2 Note About the Examples in This Book 2-3 BALANCED-EXPRESSION 2-5 CHARACTER 2-9 058059 Tandem Computers
    [Show full text]
  • RECEIPTS and CONTRACTS Bureau of Driver Training Programs Commissioner Regulations Part 76.8, Records and Contracts — Highlights Regarding
    RECEIPTS AND CONTRACTS Bureau of Driver Training Programs Commissioner Regulations Part 76.8, Records and Contracts — Highlights Regarding RECEIPT [Section 76.8 (a)(3) and (d)] A receipt is to be issued each time money is paid. Every receipt must show: u Name and address of the school u Amount paid u Duration of each lesson u Receipt number u Service rendered u Signature of an authorized representative of u Name of student u Contract number, if any the school u Date of payment The name and address of the school, and the receipt number, must be preprinted. Receipt numbers must be in sequence. The original receipt is given to the student; the duplicate is retained by the school in numeric order. Each contract or, if no contract is used, each receipt issued to a student, must include the following statement concerning refunds: (1) Except for contracts executed by schools licensed by the New York State Education Department and subject to the refund provisions of regulations promulgated by that Department, prepayment for lessons and other services shall be subject to refund as follows: if the student, having given prior notice of at least 24 hours, withdraws from or discontinues a prepaid course of instruction or series of lessons before completion thereof, or from any other service for which prepayment has been made, or if the school is unable or unwilling to complete such prepaid course of instruction, or series of lessons, or to provide such other prepaid service, all payments made by the student to the school shall be refunded except: (i) an amount equal to the enrollment fee, if any, specified in the contract or expressly receipted for, not to exceed the sum of $10 or 10 percent of the total, whichever is greater, specified cost of such course of instruction or series of lessons; and (ii) the school’s per-lesson tuition charge for each lesson already taken by the student which charge shall be determined by dividing the total cost of such course of instruction or series of lessons by the number of lessons included therein.
    [Show full text]
  • Command $Line; Done
    http://xkcd.com/208/ >0 TGCAGGTATATCTATTAGCAGGTTTAATTTTGCCTGCACTTGGTTGGGTACATTATTTTAAGTGTATTTGACAAG >1 TGCAGGTTGTTGTTACTCAGGTCCAGTTCTCTGAGACTGGAGGACTGGGAGCTGAGAACTGAGGACAGAGCTTCA >2 TGCAGGGCCGGTCCAAGGCTGCATGAGGCCTGGGGCAGAATCTGACCTAGGGGCCCCTCTTGCTGCTAAAACCAT >3 TGCAGGATCTGCTGCACCATTAACCAGACAGAAATGGCAGTTTTATACAAGTTATTATTCTAATTCAATAGCTGA >4 TGCAGGGGTCAAATACAGCTGTCAAAGCCAGACTTTGAGCACTGCTAGCTGGCTGCAACACCTGCACTTAACCTC cat seqs.fa PIPE grep ACGT TGCAGGTATATCTATTAGCAGGTTTAATTTTGCCTGCACTTGGTTGGGTACATTATTTTAAGTGTATTTGACAAG >1 TGCAGGTTGTTGTTACTCAGGTCCAGTTCTCTGAGACTGGAGGACTGGGAGCTGAGAACTGAGGACAGAGCTTCA >2 TGCAGGGCCGGTCCAAGGCTGCATGAGGCCTGGGGCAGAATCTGACCTAGGGGCCCCTCTTGCTGCTAAAACCAT >3 TGCAGGATCTGCTGCACCATTAACCAGACAGAAATGGCAGTTTTATACAAGTTATTATTCTAATTCAATAGCTGA >4 TGCAGGGGTCAAATACAGCTGTCAAAGCCAGACTTTGAGCACTGCTAGCTGGCTGCAACACCTGCACTTAACCTC cat seqs.fa Does PIPE “>0” grep ACGT contain “ACGT”? Yes? No? Output NULL >1 TGCAGGTTGTTGTTACTCAGGTCCAGTTCTCTGAGACTGGAGGACTGGGAGCTGAGAACTGAGGACAGAGCTTCA >2 TGCAGGGCCGGTCCAAGGCTGCATGAGGCCTGGGGCAGAATCTGACCTAGGGGCCCCTCTTGCTGCTAAAACCAT >3 TGCAGGATCTGCTGCACCATTAACCAGACAGAAATGGCAGTTTTATACAAGTTATTATTCTAATTCAATAGCTGA >4 TGCAGGGGTCAAATACAGCTGTCAAAGCCAGACTTTGAGCACTGCTAGCTGGCTGCAACACCTGCACTTAACCTC cat seqs.fa Does PIPE “TGCAGGTATATCTATTAGCAGGTTTAATTTTGCCTGCACTTG...G” grep ACGT contain “ACGT”? Yes? No? Output NULL TGCAGGTTGTTGTTACTCAGGTCCAGTTCTCTGAGACTGGAGGACTGGGAGCTGAGAACTGAGGACAGAGCTTCA >2 TGCAGGGCCGGTCCAAGGCTGCATGAGGCCTGGGGCAGAATCTGACCTAGGGGCCCCTCTTGCTGCTAAAACCAT >3 TGCAGGATCTGCTGCACCATTAACCAGACAGAAATGGCAGTTTTATACAAGTTATTATTCTAATTCAATAGCTGA
    [Show full text]
  • Presentation of the Results at HCVS on March 28
    Report on the 2021 edition Philipp Rümmer & Grigory Fedyukovich Outline ● Tracks and Benchmarks ● Teams and Solvers ● Results Tracks ● Linear Integer Arithmetic (LIA), linear clauses (LIA-Lin) ● LIA, nonlinear clauses (LIA-Nonlin) ● LIA and Arrays, linear clauses (LIA-Lin-Array) ● LIA and Arrays, nonlinear clauses (LIA-Nonlin-Array) ● Linear Real Arithmetic (LRA), transition systems (LRA-TS) ● LRA, transition systems, parallel (LRA-TS-Parallel) ● Algebraic Data Types (ADT), nonlinear (ADT-Nonlin) Tracks ● Linear Integer Arithmetic (LIA), linear clauses (LIA-Lin) ● LIA, nonlinear clauses (LIA-Nonlin) ● LIA and Arrays, linear clauses (LIA-Lin-Array) ● LIA and Arrays, nonlinear clauses (LIA-Nonlin-Array) ● Linear Real Arithmetic (LRA), transition systems (LRA-TS) ● LRA, transition systems, parallel (LRA-TS-Parallel) ● Algebraic Data Types (ADT), nonlinear (ADT-Nonlin) New in 2021 The Benchmarks New Benchmarks in 2021 ● Spacer ○ ADT+LIA benchmarks from Rust verification problems (post-processed afterwards) ○ LIA-Nonlin-Arrays benchmarks from SeaHorn ● RInGen ○ (Pure) ADT benchmarks from well-known TIP/Isaplanner suites ● FreqHorn ○ LIA-Lin benchmarks from the paper ● ADTCHC ○ Benchmarks from the paper ● NayHorn ○ LIA-NonLin benchmarks encoding syntax-guided synthesis problems ● SemGuS ○ LIA-NonLin-Arrays benchmarks encoding synthesis problems Benchmark Processing ● Benchmarks were selected among those available on https://github.com/chc-comp ● Processing for ADT-NonLin: ○ Purification e.g., to replace INT by NAT and SMT functions by recursive
    [Show full text]
  • The Intercal Programming Language Revised Reference Manual
    THE INTERCAL PROGRAMMING LANGUAGE REVISED REFERENCE MANUAL Donald R. Woods and James M. Lyon C-INTERCAL revisions: Louis Howell and Eric S. Raymond Copyright (C) 1973 by Donald R. Woods and James M. Lyon Copyright (C) 1996 by Eric S. Raymond Redistribution encouragedunder GPL (This version distributed with C-INTERCAL 0.15) -1- 1. INTRODUCTION The names you are about to ignore are true. However, the story has been changed significantly.Any resemblance of the programming language portrayed here to other programming languages, living or dead, is purely coincidental. 1.1 Origin and Purpose The INTERCAL programming language was designed the morning of May 26, 1972 by Donald R. Woods and James M. Lyon, at Princeton University.Exactly when in the morning will become apparent in the course of this manual. Eighteen years later (give ortakeafew months) Eric S. Raymond perpetrated a UNIX-hosted INTERCAL compiler as a weekend hack. The C-INTERCAL implementation has since been maintained and extended by an international community of technomasochists, including Louis Howell, Steve Swales, Michael Ernst, and Brian Raiter. (There was evidently an Atari implementation sometime between these two; notes on it got appended to the INTERCAL-72 manual. The culprits have sensibly declined to identify themselves.) INTERCAL was inspired by one ambition: to have a compiler language which has nothing at all in common with anyother major language. By ’major’ was meant anything with which the authors were at all familiar,e.g., FORTRAN, BASIC, COBOL, ALGOL, SNOBOL, SPITBOL, FOCAL, SOLVE, TEACH, APL, LISP,and PL/I. For the most part, INTERCAL has remained true to this goal, sharing only the basic elements such as variables, arrays, and the ability to do I/O, and eschewing all conventional operations other than the assignment statement (FORTRAN "=").
    [Show full text]
  • Your Contractual Questions Answered
    Your Contractual Questions Answered. Entrusty Group, a multi-displinary group of companies, of which, one of their specialisation is in project, commercial and contractual management, has been running a regular contractual questions and answers section for Master Builders members in the Master Builders Journal. In this instalment of this series, Entrusty Group will provide the answer to the frequently asked question - When must retention sum be released and paid ? Most if not all construction contracts used around the world usually have provisions for the retention of a certain amount of monies due to the Contractor by the Employer. This retention sum is normally retained by the Employer throughout the contract period and usually beyond the construction period up to the expiry of the defects liability period. Release of the retention sum is usually done in two portions. The first, called the one moiety, where half the retention sum is usually released with the issuance of the Certificate of Practical Completion and the remainder is usually released after expiry of the defects liability period and the issuance of Certificate of Making Good Defects by the Architect/Engineer/SO. Retention sums however, may be subjected to set-off by the Employer in accordance with the provisions in the contract. Standard Forms of Contract (Relevant Clauses) PAM Form of Building Contract Under PAM 98’s Clause 30.4 (69 – Cl.30(3)), it allows the Employer to retain a percentage of the total value of works, materials or goods as retention monies. The said percentage is stated in the Appendix as Percentage of Certified Value Retained.
    [Show full text]
  • Introduction to BASH: Part II
    Introduction to BASH: Part II By Michael Stobb University of California, Merced February 17th, 2017 Quick Review ● Linux is a very popular operating system for scientific computing ● The command line interface (CLI) is ubiquitous and efficient ● A “shell” is a program that interprets and executes a user's commands ○ BASH: Bourne Again SHell (by far the most popular) ○ CSH: C SHell ○ ZSH: Z SHell ● Does everyone have access to a shell? Quick Review: Basic Commands ● pwd ○ ‘print working directory’, or where are you currently ● cd ○ ‘change directory’ in the filesystem, or where you want to go ● ls ○ ‘list’ the contents of the directory, or look at what is inside ● mkdir ○ ‘make directory’, or make a new folder ● cp ○ ‘copy’ a file ● mv ○ ‘move’ a file ● rm ○ ‘remove’ a file (be careful, usually no undos!) ● echo ○ Return (like an echo) the input to the screen ● Autocomplete! Download Some Example Files 1) Make a new folder, perhaps ‘bash_examples’, then cd into it. Capital ‘o’ 2) Type the following command: wget "goo.gl/oBFKrL" -O tutorial.tar 3) Extract the tar file with: tar -xf tutorial.tar 4) Delete the old tar file with rm tutorial.tar 5) cd into the new director ‘tutorial’ Input/Output Redirection ● Typically we give input to a command as follows: ○ cat file.txt ● Make the input explicit by using “<” ○ cat < file.txt ● Change the output by using “>” ○ cat < file.txt > output.txt ● Use the output of one function as the input of another ○ cat < file.txt | less BASH Utilities ● BASH has some awesome utilities ○ External commands not
    [Show full text]
  • MPI Programming — Part 2 Objectives
    MPI Programming | Part 2 Objectives • Barrier synchronization • Broadcast, reduce, gather, scatter • Example: Dot product • Derived data types • Performance evaluation 1 Collective communications In addition to point-to-point communications, MPI includes routines for performing collective communications, i.e., communications involving all processes in a communicator, to allow larger groups of processors to communicate, e.g., one-to-many or many-to-one. These routines are built using point-to-point communication routines, so in principle you could build them yourself. However, there are several advantages of directly using the collective communication routines, including • The possibility of error is reduced. One collective routine call replaces many point-to-point calls. • The source code is more readable, thus simplifying code debugging and maintenance. • The collective routines are optimized. 2 Collective communications Collective communication routines transmit data among all processes in a communicator. It is important to note that collective communication calls do not use the tag mechanism of send/receive for associating calls. Rather, calls are associated by the order of the program execution. Thus, the programmer must ensure that all processes execute the same collective communication calls and execute them in the same order. The collective communication routines can be applied to all processes or a specified set of processes as defined in the communicator. For simplicity, we assume all processes participate in the collective communications, but it is always possible to define a collective communication between a subset of processes with a suitable communicator. 3 MPI Collective Communication Routines MPI provides the following collective communication routines: • Barrier sychronization across all processes.
    [Show full text]
  • IBM ILOG CPLEX Optimization Studio OPL Language Reference Manual
    IBM IBM ILOG CPLEX Optimization Studio OPL Language Reference Manual Version 12 Release 7 Copyright notice Describes general use restrictions and trademarks related to this document and the software described in this document. © Copyright IBM Corp. 1987, 2017 US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Trademarks IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml. Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, and/or other countries. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. UNIX is a registered trademark of The Open Group in the United States and other countries. Microsoft, Windows, Windows NT, and the Windows logo are trademarks of Microsoft Corporation in the United States, other countries, or both. Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates. Other company, product, or service names may be trademarks or service marks of others. © Copyright IBM Corporation 1987, 2017. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Figures ............... v Limitations on constraints ........ 59 Formal parameters ...........
    [Show full text]
  • Gnu Coreutils Core GNU Utilities for Version 6.9, 22 March 2007
    gnu Coreutils Core GNU utilities for version 6.9, 22 March 2007 David MacKenzie et al. This manual documents version 6.9 of the gnu core utilities, including the standard pro- grams for text and file manipulation. Copyright c 1994, 1995, 1996, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". Chapter 1: Introduction 1 1 Introduction This manual is a work in progress: many sections make no attempt to explain basic concepts in a way suitable for novices. Thus, if you are interested, please get involved in improving this manual. The entire gnu community will benefit. The gnu utilities documented here are mostly compatible with the POSIX standard. Please report bugs to [email protected]. Remember to include the version number, machine architecture, input files, and any other information needed to reproduce the bug: your input, what you expected, what you got, and why it is wrong. Diffs are welcome, but please include a description of the problem as well, since this is sometimes difficult to infer. See section \Bugs" in Using and Porting GNU CC. This manual was originally derived from the Unix man pages in the distributions, which were written by David MacKenzie and updated by Jim Meyering.
    [Show full text]