### 编写适当的自定义读取实例

``````data Position      =  Position (Absc,Ordn) deriving (Show)
let absc = List.filter (/='(') \$ takeWhile (/=',')
ordn = List.filter (/=')') \$ tail (dropWhile (/=',') )
in (\str -> Position ( (read (absc str) :: Int)
, (read (ordn str) :: Int) ) ) input
type Absc = Int
type Ordn = Int
``````

``````• Couldn't match expected type ‘[Char]’
with actual type ‘[Char] -> [Char]’
• Probable cause: ‘takeWhile’ is applied to too few arguments
In the second argument of ‘(\$)’, namely ‘takeWhile (/= ',')’
In the expression: filter (/= '(') \$ takeWhile (/= ',')
In an equation for ‘absc’:
absc = filter (/= '(') \$ takeWhile (/= ',')
``````

``````• Couldn't match expected type ‘[(Position, String)]’
with actual type ‘Position’
• In the expression:
(\ str
-> Position ((read (absc str) :: Int), (read (ordn str) :: Int)))
input
In the expression:
let
absc = filter (/= '(') \$ takeWhile (/= ',')
ordn = filter (/= ')') \$ tail (dropWhile (/= ','))
in
(\ str
-> Position ((read (absc str) :: Int), (read (ordn str) :: Int)))
input
= let
absc = filter (/= '(') \$ takeWhile (/= ',')
ordn = filter (/= ')') \$ tail (dropWhile (/= ','))
in
(\ str
-> Position ((read (absc str) :: Int), (read (ordn str) :: Int)))
input
``````

## 修复代码

``````instance Read Position where
let absc = filter (/='(') . takeWhile (/=',')
ordn = filter (/=')') . tail . dropWhile (/=',')
in [(Position ( read (absc input) :: Int
, read (ordn input) :: Int), input)]
``````

## 整理

``````instance Read Position where
readsPrec _ str = let ('(':absc,',':ordn') = break (==',') str
(ordn,')':str') = break (==')') ordn'
``````

## 使用现有功能

``````instance Read Position where
readsPrec s str = [(Position x, rest) | (x,rest) <- readsPrec s str]
``````

## 很好，但我们仍然可以做得更好

``````instance Read Position where