系列: haskell
haskell
57 行
· 更新于 2026-02-03
Type.hs
haskell/Week9/Type.hs
{-|
Module : Type
Author : COMP1100 Team, Your name and UID here
Date :
Description : Exercises with types
-}
module Type where
{-
Exercise 1: (Optional)
Work out the type classes for the following types.
The first one has been done for you.
Integer (Integral)
Double (?)
Char (?)
Bool (?)
(Integer, Integer) (?)
(Integer, Double) (?)
String (?)
[Integer] (?)
Integer -> Integer (?)
Maybe Integer (?)
-}
{-
Exercise 2:
What are the types of these functions?
(Don't just cheat and punch it in GHCi. Try to work it out yourself.)
-}
--cow :: ???
cow :: Bool -> Char -> String -> Bool
cow x y z = x && (elem y z)
--foo :: ???
foo :: Char -> String -> [String] -> Bool
foo x y z = (elem x y) && (elem y z)
--bar :: ???
bar :: Num a => a -> Maybe a -> a
bar x y = case y of
Nothing -> x
Just z -> x + z
-- snap :: ???
snap :: (Show a, Ord a) => a -> a -> String
snap x y
| x > y = show x
| otherwise = show y
相关文章
haskell
haskell
更新于 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
阅读文章 →
haskell
haskell
更新于 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
阅读文章 →
haskell
haskell
更新于 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
阅读文章 →
haskell
haskell
更新于 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
阅读文章 →
haskell
haskell
更新于 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
阅读文章 →
haskell
haskell
更新于 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
阅读文章 →