haskell - write haskell modules and load/import in ghci

You may want to write up some haskell modules and put it into the interactive ghci command prompt so that you can see how it works out... it is more  a repl things.

suppose that you have write the following modules.

-- file:
--   Person.hs
-- description:
--   the file defines the Person object

module Person
( Person(..)
, firstName
, lastName
, age
, height
, phoneNumber
, flavor
) where

data Person = Person String String Int Float String String deriving (Show)

firstName :: Person -> String
firstName (Person firstName _ _ _ _ _) = firstName

lastName :: Person -> String
lastName (Person _ lastName _ _ _ _) = lastName

age :: Person -> Int
age (Person _ _ age _ _ _ ) = age

height :: Person -> Float
height (Person _ _ _ height _ _) = height

phoneNumber :: Person -> String
phoneNumber (Person _ _ _ _ number _) = number

flavor :: Person -> String
flavor (Person _ _ _ _ _ flavor) = flavor

--
-- alternative way to write data types
-- with mnemonic such as follo
-- NOTE :
--  Check on the Person2.hs

 

And from the haskell command window, you may do the following

 

Prelude> :l Person.hs
[1 of 1] Compiling Person           ( Person.hs, interpreted )
Ok, modules loaded: Person.
*Person> import Person

 That is basically , first load up the file and secondly try to do the import things.

你可能感兴趣的:(haskell)