联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2018-11-30 10:08

Haskell Coursework 2018

November 27, 2018

1 Introduction

The Haskell coursework for this year is a programming challenge. This challenge

is modular: it is not necessary to complete every aspect to get a passing mark.

If a function is marked as being higher order, it should written using higher

order functions. Submit a Haskell file (extension *.hs). This file must load into

ghci without type or other errors. You must provide type signatures for all

defined functions. Finally, while it is acceptable to use functions provided by

Prelude, please write any other required functions yourself. Do not use functions

imported from libraries. While this is bad practice for real development, it is

good practice for learning.

2 Basics

A Horse is an ascii image of a horse. Learn about newtypes (via Google) and

instantiate a Horse type with at least one member, e.g.

h o r s e : : Horse

h o r s e = [ ” , / / ) ”

, ” ; ; ’ \ ”

, ” , ; ; ’ ( ’\ ”

, ” / ’\ ) ” ]

3 Rotations

Define a higher order function, transpose that takes a Horse and rotates it

90

to the right. Define another (higher order) function mirror which flips the

Horse on its vertical access. Show that it is possible to perform all possible

rotatations using just these two functions (hint: think compositionally).

1

4 Integer Sequences

Define functions to generate two mathematical sequences, such as the Fibonacci

sequence. These should be higher order functions. Hint: you may want to

look at the On-Line Encyclopedia of Integer Sequences https://oeis.org/ for

inspiration. You might want to make sure that the sequences do not grow too

quickly. Note: do not use the Fibonacci sequence!

As such sequences may be infinite, it should be possible to pass a parameter

to the functions to limit the length of the returned list.

5 IO

Write a function pretty :: Horse > IO () which takes an element of type

Horse and prints it to the terminal.

Write a function horseSeq which takes a function f, a positive integer n and

a Horse as an argument and pretty prints Horses in accordance with f, e.g.

h o r seSe q : : ( Int > [ Int ] ) > Int > Horse > IO ( )

h o r seSe q f n h = . . .

h o r seSe q f i b o n a c c i 5 h o r s e =

no h o r s e

, / / )

; ; ’ \

, ; ; ’ ( ’\

/ ’\ )

, / / )

; ; ’ \

, ; ; ’ ( ’\

/ ’\ )

, / / ) , / / )

; ; ’ \ ; ; ’ \

, ; ; ’ ( ’\ , ; ; ’ ( ’\

/ ’\ ) / ’\ )

, / / ) , / / ) , / / )

; ; ’ \ ; ; ’ \ ; ; ’ \

, ; ; ’ ( ’\ , ; ; ’ ( ’\ , ; ; ’ ( ’\

/ ’\ ) / ’\ ) / ’\ )

6 Type Classes

What typeclass(es) does Horse belong to? Write at least one typeclass instance

for Horse.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp