Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Haskell Syntax & Key Concepts: Functions, Datatypes, Layout, Comments, Local Defs - Prof. , Study notes of Computer Science

An overview of haskell syntax and key concepts, including function and datatype names, layout rules, comments, local definitions, if-then-else statements, the standard prelude, and infix operators. It covers topics such as function definition syntax, comments, let-in bindings, and the evaluation rules for if-then-else statements.

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-uzk
koofers-user-uzk 🇺🇸

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Haskell Syntax & Key Concepts: Functions, Datatypes, Layout, Comments, Local Defs - Prof. and more Study notes Computer Science in PDF only on Docsity! COSC 3015: Lecture 5 Lecture given by Prof. Caldwell and scribed by Sunil Kothari September 16, 2008 1 Some Notes on Haskell Syntax Function names, variable names starts with lowercase letter - followed by zero or more digits, underscores ( ) upper or lowercase letters, forward quotes ()́. For example, x1, x′, x1, x′′. Datatype and datatype constructor names start with uppercase letters and are otherwise like functions and variable names. For example, Bool, String, Int , True, False. Keywords case, class, data, default, deriving, do, else, if, import, in , infix, infixl, infixr, instance, let, module, newtype, of , then, type, where. 1.1 Layout rule Each function definition must begin in the same column. a = b + c where b = 1 c = 2 d a = a* 2 a = b + c where {b = 1; c = 2} d a = a* 2 1.2 Comments Line comments start with ”–” and continue to the end of the line. For exam- ple, fx = x + 1−−dumbfunction Nested comments are of the form {− · · · −} 1 1.3 Local Definition The following code has the same effect as the ex. 1 a = let b = 1 c = 2 in b + c Here’s another version of it. a = b + c where b = 1 c = 2 Meaning of let-in. let x = t1 in t2 means t2[x := t1] where, • x is locally defined variable • t1 is local declaration of x • t2 body of the let-declaration and t2[x := t1] - evaluate expression t2 where all free occurrences of x get the value of expression t1. Note that ”:=” is a capture-avoiding substitution let x = 1 in let x = 2 in x ; 2 we can elaborate on it ∀x : Int,∀x : nat.x ≥ 0. Choose arb. y ∈ int and show ∀x : Int,∀x : nat.x ≥ 0[x := y] ; ∀x : nat, x ≥ 0 1.4 if-then-else A code fragment in an imperative language if x > 0 then y := x else y:= (-x) In C and C++ there is a conditional expression 2
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved