Getting started with Hugs on Linux

Similar documents
Getting started with Hugs on Linux

Mills HPC Tutorial Series. Linux Basics I

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

CS Fundamentals of Programming II Fall Very Basic UNIX

A Brief Introduction to Unix

CISC 220 fall 2011, set 1: Linux basics

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

Perl and R Scripting for Biologists

CSCI 2132 Software Development. Lecture 4: Files and Directories

Introduction to Linux

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

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

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

Unix Basics. Systems Programming Concepts

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

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

INSE Lab 1 Introduction to UNIX Fall 2017

Linux Systems Administration Getting Started with Linux

Introduction: What is Unix?

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

Working with Basic Linux. Daniel Balagué

Linux/Cygwin Practice Computer Architecture

Introduction to Linux

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

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

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

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.

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

UNIX Tutorial Five

Session 1: Accessing MUGrid and Command Line Basics

commandname flags arguments

Introduction to Linux

File system Security (Access Rights)

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

Lab 3a Using the vi editor

Introduction to Linux

Chapter-3. Introduction to Unix: Fundamental Commands

Linux File System and Basic Commands

15-122: Principles of Imperative Computation

Outline. Structure of a UNIX command

Commands are in black

Introduction to Linux

CS4350 Unix Programming. Outline

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.

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Introduction to the basics of UNIX

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

Files and Directories

Introduction to Linux Workshop 1

Lab 2: Linux/Unix shell

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

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

INTRODUCTION TO LINUX

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

Introduction to Linux

Getting Started with UNIX

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

Introduction of Linux

Unix Handouts. Shantanu N Kulkarni

Introduction to Linux

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

Linux Shell Script. J. K. Mandal

CHE3935. Lecture 1. Introduction to Linux

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

CS4023 Week04 Lab Exercise

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

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

5/20/2007. Touring Essential Programs

Linux at the Command Line Don Johnson of BU IS&T

Linux Command Line Interface. December 27, 2017

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.

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

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

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

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 to the Linux Command Line

AMS 200: Working on Linux/Unix Machines

CSC209. Software Tools and Systems Programming.

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

Getting your department account

Introduction to Cygwin Operating Environment

Oxford University Computing Services. Getting Started with Unix

Introduction to Unix: Fundamental Commands

The Unix Shell & Shell Scripts

Using echo command in shell script

Operating Systems. Copyleft 2005, Binnur Kurt

UNIX Quick Reference

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

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

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

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

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

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

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

You will automatically be in your user (home) directory when you login.

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

Practical Session 0 Introduction to Linux

AN INTRODUCTION TO UNIX

Transcription:

Getting started with Hugs on Linux COM1022 Functional Programming Techniques Dr Hans Georg Schaathun University of Surrey Autumn 2009 Week 7 Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2009Week 7 1 / 35

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 2009Week 7 2 / 35

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 2009Week 7 3 / 35

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 reason over computer programs. 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 2009Week 7 4 / 35

Learning Objectives The Programme Weekly lectures and labs 3 weeks @ 1h lecture + 1h lab 2 weeks @ 3h lectures + 1h lab 10 weeks @ 2h lectures + 1-2h lab Weekly exercise sheets for the labs Lab Sheet 1 for next week (preparatory exercises). Some lab exercises will have direct relevance for the coursework Coursework 5% on reasoning (theoretical) 40% programming exercise Details will be announced later. 2h written, unseen exam See http://www.computing.surrey.ac.uk/teaching/ current/comm1022/ Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2009Week 7 5 / 35

This week Learning Objectives This week will give you the basic introduction to the labs and software linux command line the editor the hugs interpreter The lecture is worth little take advantage of the lab sessions make sure that you can use the knowledge from the lecture Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2009Week 7 6 / 35

Learning Objectives References A comprehensive book (recommended): Haskell: The Craft of Functional Programming by Simon Thompson A basic book: Programming in Haskell by Graham Hutton 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 2009Week 7 7 / 35

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 2009Week 7 8 / 35

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 2009Week 7 9 / 35

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 2009Week 7 10 / 35

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 2009Week 7 11 / 35

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 2009Week 7 12 / 35

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 2009Week 7 13 / 35

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 2009Week 7 14 / 35

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 2009Week 7 15 / 35

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 2009Week 7 16 / 35

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 2009Week 7 17 / 35

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 2009Week 7 18 / 35

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 2009Week 7 19 / 35

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 2009Week 7 19 / 35

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 2009Week 7 19 / 35

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 2009Week 7 20 / 35

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 2009Week 7 21 / 35

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 2009Week 7 22 / 35

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 (the heavy-weighters) nedit, gedit (simple GUI) pico (simple in the terminal window) etc. Dr Hans Georg Schaathun Getting started with Hugs on Linux Autumn 2009Week 7 23 / 35

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 2009Week 7 24 / 35

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 2009Week 7 25 / 35

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 2009Week 7 26 / 35

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 2009Week 7 27 / 35

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 2009Week 7 28 / 35

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 2009Week 7 29 / 35

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 2009Week 7 30 / 35

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 2009Week 7 31 / 35

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 2009Week 7 31 / 35

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 2009Week 7 32 / 35

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 2009Week 7 32 / 35

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 2009Week 7 33 / 35

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 2009Week 7 34 / 35

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 2009Week 7 35 / 35