haskell - write haskell modules and load/import in ghci

本文介绍了如何在Haskell中定义一个包含个人信息如姓名、年龄等属性的Person模块,并通过ghci命令行进行加载和使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值