This repository has been archived on 2025-07-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fp/test1/Types.hs
AKP 0262b34e47
Add test 1
Squashed commit of the following:

commit 82aa61982e9c65f65f221fbbcdb41fe8a21321ec
Author: AKP <abi@tdpain.net>
Date:   Thu Nov 9 12:33:56 2023 +0000

    Question 5

commit 7239dcaa65545c9a5b8b634213c813438c8e52f8
Author: AKP <abi@tdpain.net>
Date:   Thu Nov 9 11:47:10 2023 +0000

    Question 4

commit 507520373221469ea2f71ee44b67f51dbf9a2455
Author: AKP <abi@tdpain.net>
Date:   Thu Nov 9 11:40:56 2023 +0000

    Question 3

commit 7138150a9c7f34ceb4fdb9c10a018b9cd45cb196
Author: AKP <abi@tdpain.net>
Date:   Thu Nov 9 11:11:26 2023 +0000

    Question 2

commit 808293dff53bd033ea9138ef01a4cb2dfab8fbca
Author: AKP <abi@tdpain.net>
Date:   Thu Nov 9 11:05:24 2023 +0000

    Question 1

commit 9f4b80f7e887c0b3665e95ef1be1678e116ec2bc
Author: AKP <abi@tdpain.net>
Date:   Thu Nov 9 11:00:25 2023 +0000

    Add base files
2023-11-09 13:20:21 +00:00

56 lines
1.7 KiB
Haskell

-- setting the "warn-incomplete-patterns" flag asks GHC to warn you
-- about possible missing cases in pattern-matching definitions
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
-- see https://wiki.haskell.org/Safe_Haskell
{-# LANGUAGE Safe #-}
---------------------------------------------------------------------------------
-------------------------- DO **NOT** MODIFY THIS FILE --------------------------
---------------------------------------------------------------------------------
module Types where
-- Question 2
factors :: Int -> [Int]
factors n = [ k | k <- [1..n] , n `mod` k == 0 ]
isPrime :: Int -> Bool
isPrime n = factors n == [1, n]
primeFactors :: Int -> [Int]
primeFactors n = [x | x <- [1..n], n `mod` x == 0 && isPrime x]
-- Question 3
data TrainStop = BirminghamNewStreet
| FiveWays
| University
| SellyOak
| Bournville
| KingsNorton
| Northfield
| Longbridge
| BarntGreen
| Alvechurch
| Redditch
deriving (Eq, Show)
theStopAfter :: TrainStop -> TrainStop
theStopAfter Redditch = Alvechurch
theStopAfter Alvechurch = BarntGreen
theStopAfter BarntGreen = Longbridge
theStopAfter Longbridge = Northfield
theStopAfter Northfield = KingsNorton
theStopAfter KingsNorton = Bournville
theStopAfter Bournville = SellyOak
theStopAfter SellyOak = University
theStopAfter University = FiveWays
theStopAfter FiveWays = BirminghamNewStreet
theStopAfter BirminghamNewStreet = undefined
-- Question 4
divideBy2 :: Int -> Int
divideBy2 n = n `div` 2