File: Input.hs

package info (click to toggle)
haskell-appar 0.1.8-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 76 kB
  • sloc: haskell: 160; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 865 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}

module Text.Appar.Input where

import qualified Data.ByteString.Char8 as S
import qualified Data.ByteString.Lazy.Char8 as L

----------------------------------------------------------------

{-|
  The class for parser input.
-}
class Eq inp => Input inp where
    -- | The head function for input
    car :: inp -> Char
    -- | The tail function for input
    cdr :: inp -> inp
    -- | The end of input
    nil :: inp
    -- | The function to check the end of input
    isNil :: inp -> Bool


instance Input S.ByteString where
    car   = S.head
    cdr   = S.tail
    nil   = S.empty
    isNil = S.null

instance Input L.ByteString where
    car   = L.head
    cdr   = L.tail
    nil   = L.empty
    isNil = L.null

instance Input String where
    car = head
    cdr = tail
    isNil = null
    nil = ""