lecture-03 - CMSC-16100 Lecture 3

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CMSC-16100 Lecture 3 <<For next year -- reorder this, moving much of the material to the next lecture, so as to better prepare students for the lab.>> Remember the lab today. It is insanely ambitious, but I think you'll feel a real sense of accomplishment when you finish it. But to get there, we have a lot to do. .. Fundamentals of the Haskell Type System. Values (possible results of computations) are naturally grouped into *types*. Stated somewhat differently, a type is a set of values. But not an arbitrary set! 1. Bool -- the type for boolean values data Bool = False | True [Note that type names always start with a capital letter. The same is true for constructors -- of which True and False are a special case.] There are a few pre-defined functions that work on Booleans: 2. Char -- the type for characters Here's a place where the distinction between hugs and ghc matters. The character functions in ghc are not a part of the default module (more on this later), but instead are a part of the Char module. 'a', 'b' -- representative elements of Char type. Prelude> import Char -- use Char module defs Prelude> isDigit 'a' False Prelude> isDigit '0' True If you look up the Haskell98 report, you'll find a lot of other predefined functions -- isUpper, toUpper, ord, chr -- and friends. Note that modules also always start with a capital letter, and functions always start with a lower-case letter. This is not optional. Prelude> ord 'a' 97 Prelude> chr 97 'a' 3. String -- the type for strings Prelude> "foo" ++ "bar" "foobar" For now, there isn't too much you can do with strings. You can test them for equality and order, and you can concatenate them. Other capabilities will
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
become apparent very soon! 4. Integral Types Numerics and computer programming languages get along uneasily. The problem is that we want it to be easy to deal with numbers, but in fact there are several different number systems we tend to use, and ordinarily without thinking about it very much. And when you add issues of time and space efficiency to the mix, the situation gets even more difficult. The solution, such as it is, seems to be to figure out what kind of number you're working with, and clue the system in. Integer -- so called "infinite precision" integers, there is no a priori bound on how big they can be. For example: Prelude> product [1. .1000] -- a 2568 digit number -- Int -- "machine precision" (usually 32-bit 2s complement, will probably become 64 bits before you graduate). Note that integral types support div, but not /.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

lecture-03 - CMSC-16100 Lecture 3

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online