Getting started with Hugs on Linux

Similar documents
Getting started with Hugs on Linux

Mills HPC Tutorial Series. Linux Basics I

A Brief Introduction to Unix

Perl and R Scripting for Biologists

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

CS Fundamentals of Programming II Fall Very Basic UNIX

CSCI 2132 Software Development. Lecture 4: Files and Directories

CISC 220 fall 2011, set 1: Linux basics

Chapter-3. Introduction to Unix: Fundamental Commands

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Introduction to Linux

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

First of all, these notes will cover only a small subset of the available commands and utilities, and will cover most of those in a shallow fashion.

Commands are in black

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

Linux Systems Administration Getting Started with Linux

Unix Basics. Systems Programming Concepts

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

commandname flags arguments

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

Introduction: What is Unix?

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

15-122: Principles of Imperative Computation

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

Linux Tutorial #6. -rw-r csce_user csce_user 20 Jan 4 09:15 list1.txt -rw-r csce_user csce_user 26 Jan 4 09:16 list2.

Introduction to Unix: Fundamental Commands

Session 1: Accessing MUGrid and Command Line Basics

Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

Linux File System and Basic Commands

Working with Basic Linux. Daniel Balagué

acmteam/unix.pdf How to manage your account (user ID, password, shell); How to compile C, C++, and Java programs;

Virtual Machine. Linux flavor : Debian. Everything (except slides) preinstalled for you.

Files and Directories

Linux/Cygwin Practice Computer Architecture

The Unix Shell & Shell Scripts

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Linux Command Line Interface. December 27, 2017

Introduction to Linux

Introduction to Linux

INSE Lab 1 Introduction to UNIX Fall 2017

Linux Shell Script. J. K. Mandal

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

Introduction to Unix. University of Massachusetts Medical School. October, 2014

Introduction to Linux Workshop 1

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

A Brief Haskell and GHC Refresher

UNIX Quick Reference

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Getting Started with UNIX

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

CpSc 1111 Lab 1 Introduction to Unix Systems, Editors, and C

CSC209. Software Tools and Systems Programming.

CHE3935. Lecture 1. Introduction to Linux

Lab 2: Linux/Unix shell

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

AMS 200: Working on Linux/Unix Machines

Getting your department account

*nix Crash Course. Presented by: Virginia Tech Linux / Unix Users Group VTLUUG

Lab 1 Introduction to UNIX and C

CMPUT 201: Practical Programming Methodology. Guohui Lin Department of Computing Science University of Alberta September 2018

Introduction to Linux

Introduction to the basics of UNIX

5/20/2007. Touring Essential Programs

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Unix Handouts. Shantanu N Kulkarni

ACS Unix (Winter Term, ) Page 92

Introduction to Linux

CS4023 Week04 Lab Exercise

CS246 Spring14 Programming Paradigm Notes on Linux

Oxford University Computing Services. Getting Started with Unix

Introduction to the Linux Command Line

COMP s1 Lecture 1

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Operating Systems. Copyleft 2005, Binnur Kurt

UNIX Tutorial Five

CS4350 Unix Programming. Outline

Introduction to Linux

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Practical Session 0 Introduction to Linux

Introduction of Linux

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

Introduction to UNIX Shell Exercises

File system Security (Access Rights)

STA 303 / 1002 Using SAS on CQUEST

Exploring UNIX: Session 3

Lab 1 Introduction to UNIX and C

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

CSC209. Software Tools and Systems Programming.

Week Overview. Unix file system File types and file naming Basic file system commands: pwd,cd,ls,mkdir,rmdir,mv,cp,rm man pages

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Outline. Structure of a UNIX command

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

Unix basics exercise MBV-INFX410

Introduction to Linux

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Transcription:

Getting started with Hugs on Linux CS190 Functional Programming Techniques Dr Hans Georg Schaathun University of Surrey Autumn 2008 Week 1 Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 1 / 43

Outline 1 Learning Objectives 2 File tree and command line 3 Software 4 The editor 5 Haskell Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 2 / 43

Outline Learning Objectives 1 Learning Objectives 2 File tree and command line 3 Software 4 The editor 5 Haskell Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 3 / 43

Learning Objectives Learning Objectives From the module description At the end of the module, the students will be able to work with standard command-line interfaces. write programs employing the fundamental features of Haskell. be able to make and use reusable functions as a fundamental building block of software development. understand recursion and polymorphism and be able to use them in simple algorithm design. contrast functional and imperative languages and understand the advantages and disadvantages of each. Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 4 / 43

The lab exercises Learning Objectives Weekly lab sessions one exercise set per week Lab Sheet 1 for next week (preparatory exercises). Portfolios Containing Haskell functions from the weekly labs Must be passed Portfolio 1 (Lab Sheet 2 for Weeks 2-4). Public test script (TBC) Portfolio 2 (Lab Sheet 3 for Weeks 5-8). Secret test script (TBC) Exact details will be announced later. Including assessment criteria See http://www.computing.surrey.ac.uk/teaching/ current/cs190/ Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 5 / 43

Learning Objectives The exam The mark is decided purely by the exam... though you will fail if you fail on a portfolio 2h written, unseen exam You need the practical understanding from the labs The exercise material is central for the exam If you master the exercises, a catastrophe is unlikely... but the exam will have something extra Extra exercises will help you Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 6 / 43

This session Learning Objectives This sessions will give you the basic background to start using the faculty linux system start using the hugs Haskell interpreter During this week you have to try the software in the linux labs make sure that you can use the knowledge from the lecture Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 7 / 43

Learning Objectives References A basic book: Programming in Haskell by Graham Hutton A comprehensive book: Haskell: The Craft of Functional Programming by Simon Thompson You ll need one of the books http://www.haskell.org You can download a copy of hugs Reference on Unix/Linux (e.g. Unix in a Nutshell [O Reilly]) Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 8 / 43

Outline File tree and command line 1 Learning Objectives 2 File tree and command line 3 Software 4 The editor 5 Haskell Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 9 / 43

File tree and command line The command line (shell) Open a terminal window Applications System Terminal... emulates an old-fashioned text terminal (tty) An interpreter (or shell) runs in the terminal reads and interprets commands Different interpreters are available: bash, tcsh, ksh, zsh Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 10 / 43

File tree and command line The file tree research/ teaching/ Notes/ labs/ Mail/ bin/ Papers/ work/ Mail/ cs190/ cs168/ css1hs/ cscssst/ css1ht/ eps351/ epsguest/ bin/ lib/ filer2/ filer6/ bin/ man/ local/ home/ tmp/ usr/ / Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 11 / 43

File tree and command line Navigating in the tree The files are organised in a tree Each node is either a directory, containing files and/or other directories a file, containing data for some piece of software Current Working Directory your location in the tree Useful commands: pwd : print current directory cd : change directory ls : list directory contents Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 12 / 43

Naming a node File tree and command line A file/directory is identified by its path Name each directory traversed to reach the file separated by slashes (/) A relative path starts from the current directory e.g. cs190/test.hs.. identifies the parent directory Absolute paths starts at the root (/) /home/filer6/epsguest/eps351/cs190/test.hs Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 13 / 43

File tree and command line Path: /home/filer6/epsguest/eps351/cs190/ research/ teaching/ Notes/ labs/ Mail/ bin/ Papers/ work/ Mail/ cs190/ cs168/ css1hs/ cscssst/ css1ht/ eps351/ epsguest/ bin/ lib/ filer2/ filer6/ bin/ man/ local/ home/ tmp/ usr/ / Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 14 / 43

File tree and command line Modifying the tree mkdir : make new directory rmdir : remove (empty) directory rm : remove file cp : copy file mv : move file For more information you can use the man pages man cp man man It takes some time to learn to read the man pages though Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 15 / 43

File information File tree and command line % ls -l total 12 drwxr-sr-x 2 eps351 epsguest 4096 Aug 6 13:25 labs/ drwxr-sr-x 2 eps351 epsguest 4096 Aug 6 13:25 Notes/ -rw------- 1 eps351 epsguest 0 Aug 6 13:26 test2.h -rw-r--r-- 1 eps351 epsguest 8 Aug 6 13:25 test.hs File type: d for directory, - for regular file Nine characters for mode (access permissions) Number of links to the file File owner (eps351) and group (epsguest) File size (bytes) Time of last modification Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 16 / 43

File tree and command line File mode (access permissions) drwxr-sr-x 2 eps351 epsguest 4096 Aug 6 13:25 Notes/ Three user classes: user/owner (char 2-4) group (char 5-7) others (char 8-10) Three access rights: r for read w for write x (or s) for execute (programs) or open (directories) chmod : change mode chmod g+w test.hs gives (+) the group (g) the write access (w) u/g/o/a [+/-/=] [r/w/x] Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 17 / 43

Outline Software 1 Learning Objectives 2 File tree and command line 3 Software 4 The editor 5 Haskell Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 18 / 43

Running other software Software Any program can be launched from the command line Some create their own window: firefox & emacs & Some run in the terminal and shell: man man vim myfile.hs find. -name myexercise.hs -print Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 19 / 43

Software Background and Foreground What does the ampersand mean? Starting a program in the foreground: emacs Starting a program in the background: emacs & Only have one foreground process and then, it cannot do anything else When a program runs in the background, the shell continues doing other things (i.e. new prompt) Programs running in the terminal window needs the foreground Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 20 / 43

Software Background and Foreground What does the ampersand mean? Starting a program in the foreground: emacs Starting a program in the background: emacs & Only have one foreground process and then, it cannot do anything else When a program runs in the background, the shell continues doing other things (i.e. new prompt) Programs running in the terminal window needs the foreground Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 20 / 43

Software Background and Foreground What does the ampersand mean? Starting a program in the foreground: emacs Starting a program in the background: emacs & Only have one foreground process and then, it cannot do anything else When a program runs in the background, the shell continues doing other things (i.e. new prompt) Programs running in the terminal window needs the foreground Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 20 / 43

Software Moving to the background Special keys in the terminal only Interrupt: Ctrl-C (terminates the program) Suspend: Ctrl-Z (program stops, but can rewake) Rewaking a process: Background: bg Foreground: fg List jobs: jobs bg %jobno. If you forget the ampersand: Ctrl-Z + bg If you suspend a terminal program: fg Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 21 / 43

Software Processes and kill List processes: Current terminal: ps All: ps xg Note PID (process ID) to the left Kill a process: Terminate: kill PID or kill %jobno. Kill: kill -KILL (and PID or job no.) Dynamic process list: top shows resource expenditure If a process malfunctions, you can kill it. Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 22 / 43

Outline The editor 1 Learning Objectives 2 File tree and command line 3 Software 4 The editor 5 Haskell Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 23 / 43

The editor The editor The editor is our most important tool Edit plain text files in Haskell, Java, C, English, HTML no special formatting (i.e. not a word-processor) Use your favourite editor emacs, vim, pico, etc. Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 24 / 43

The editor emacs Straight forward for most users Uni-modal editor Runs in a separate window (with menus etc.) It is a powerful tool Advanced editing Macros Plugins for email, news, etc Advanced features are hard to learn and few use them Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 25 / 43

The editor vim Bimodal editor Alien for many users Many commands at few key strokes Command mode all keys are used for commands (movement, replace, etc) Insert mode Typed text is added to the file Runs on the command line: very fast Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 26 / 43

The editor Basics in vim/vi Start it: vim filename.hs Command mode Insert mode: i, I, a, A, o, O Insert mode Command mode: Esc Colon commands are followed by return: Quit: :q (:q! forced) Save and quit: :wq Search and replace: :%s/old/new/g Delete: x, X (character), dd (line) Replace: r (character), R (several character (insert mode)) See a full tutorial on the web page. Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 27 / 43

The editor Starting the editor on a file A file can be given on the command line vi myfile.hs starts vi on the given file Editors running in the terminal (vi, pico) are almost always started this way You can also run emacs myfile.hs but many prefer loading the files from the menus because emacs is heavy, subsequent files should be loaded from the menu quitting and restarting is impractical vi users often prefer quit and restart Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 28 / 43

Outline Haskell 1 Learning Objectives 2 File tree and command line 3 Software 4 The editor 5 Haskell Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 29 / 43

Haskell The interpreter Start hugs on the command line different prompt Reads and interprets commands and expressions :load module.hs 56+3*9-7 "Hello World!" "Hello" ++ ", " ++ "George" You can use it straight away as a calculator... but you d rather want to make your own module with advanced features Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 30 / 43

Expressions Haskell An expression can be A single number: 42 or 12.4 An operator with arguments: 12 + 4 or 54.2/3 A function call: sqrt 12 ( 12) When you type an expresion, it is evaluated, i.e. functions and operators are applied to produce a result the result is displayed if possible Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 31 / 43

What is a function? Haskell x 1 function y 1 View the function as a machine A value x 1 comes in A value y 1 is returned Using a function, it is a black box You don t know what happens inside You see only the output y 1. Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 32 / 43

What is a function? Haskell x 1 function y 1 View the function as a machine A value x 1 comes in A value y 1 is returned Using a function, it is a black box You don t know what happens inside You see only the output y 1. Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 32 / 43

For example? Haskell 2 sqrt ( ) 1.4142135623731 Main> sqrt 2 1.4142135623731 Main> Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 33 / 43

Functional programming Haskell Functions are the fundamental building block in functional programming Contrary to imperative programming (e.g. Java)... where data objects are the building blocks During the module we will see how functions return functions functions are arguments to functions Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 34 / 43

Haskell Scripts Defining functions and constants Haskell Haskell scripts: e.g. demo.hs Edit scripts using an editor (vim, emacs) Load the script in hugs using :load The script contains definitions not expressions Note that you cannot make definitions on the command line only expressions Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 35 / 43

Haskell Scripts Defining functions and constants Haskell Haskell scripts: e.g. demo.hs Edit scripts using an editor (vim, emacs) Load the script in hugs using :load The script contains definitions not expressions Note that you cannot make definitions on the command line only expressions Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 35 / 43

Haskell Definitions and declarations Declaration: myname :: String Definition: myname = "George" This is not similar to Java = denotes equality it is a universal truth in Java = denotes an assignment and myname could then be reassigned a definition is done once and for all Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 36 / 43

Haskell Definitions and declarations Declaration: myname :: String Definition: myname = "George" This is not similar to Java = denotes equality it is a universal truth in Java = denotes an assignment and myname could then be reassigned a definition is done once and for all Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 36 / 43

Haskell Function definitions treble :: treble x = 3*x Int -> Int Hugs> :load 01intro/demo.hs Main> myname "George" Main> treble 5 15 Main> treble 4.3 ERROR - Cannot infer instance *** Instance : Fractional Int *** Expression : treble 4.3 Main> Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 37 / 43

Haskell Lists mylist :: [Int] mylist = [12, 15, 24, 14, 12, 6] Standard functions and operators exist for lists Main> mylist!!2 24 Main> reverse mylist [6,12,14,24,15,12] Main> drop 4 mylist [12,6] Main> drop (2*2) (reverse mylist) [15,12] Main> Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 38 / 43

Haskell Naming requirements Haskell is case sensitive Haskell is case sensitive mylist and mylist are different variables Case gives information about the identifier all variables start with lower-case : mylist all type identifiers start with upper-case : Int If you forget this, you will get confusing error messages... Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 39 / 43

Haskell The layout rule How does the interpreter know where a definition ends? In Java this is marked by a semicolon (;) Haskell uses layout, i.e. indentation fun x y = a long and winding expression in x + y fun2 x y = another function in x and y lines with extra indentation continues the definition any text in the same column or to the left marks a new definition Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 40 / 43

Haskell Good practice Use indentation consistently Try to make it easy to read max x y x > y = x otherwise = y Align the guards ( ) and the equal signs (=) Layout is mainly a question of personal style... but please think of the reader Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 41 / 43

Comments Haskell Good practice: comment your code Comment starts with - and ends at the end of line - the compiler ignore comments like this Comments are for human readers explain your code make it easy to understand Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 42 / 43

Summary Haskell Quick overview of basic features and tools needed You will have to test it all on the computer lab sessions and in your own time This week s material is basic you have to master it Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2008Week 1 43 / 43