Skip to content

Commit 2962840

Browse files
committed
Add Ord instance for Data.Text
1 parent 23c0a2e commit 2962840

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

fay-base/src/Data/Text.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS -fno-warn-missing-methods #-}
12
{-# LANGUAGE DeriveDataTypeable #-}
23
{-# LANGUAGE EmptyDataDecls #-}
34
{-# LANGUAGE NoImplicitPrelude #-}
@@ -62,14 +63,15 @@ module Data.Text
6263
import Data.Data
6364
import FFI
6465
import Data.Nullable (fromNullable)
65-
import Prelude (Eq,String,Int,Bool,Char,Maybe,Double,error)
66+
import Prelude (Eq,String,Int,Bool,Char,Maybe,Double,Ord,error)
6667
import qualified "base" Data.String as B (IsString (..))
6768

6869
-- | A space efficient, packed, unboxed Unicode text type.
6970
data Text
7071
deriving instance Eq Text
7172
deriving instance Data Text
7273
deriving instance Typeable Text
74+
instance Ord Text
7375
instance B.IsString Text where fromString = error "the method fromString can never be called"
7476

7577
-- | O(n) The intercalate function takes a Text and a list of Texts and

tests/TextOrd.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE PackageImports #-}
3+
{-# LANGUAGE RebindableSyntax #-}
4+
module TextOrd where
5+
6+
import "fay-base" Data.Text
7+
8+
main :: Fay ()
9+
main = do
10+
print ("abc" < ("c"::Text))
11+
print ("a" < ("bcd"::Text))
12+
print ("bcd" > ("a"::Text))
13+
print ("bcd" < ("a"::Text))

tests/TextOrd.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
true
2+
true
3+
true
4+
false

0 commit comments

Comments
 (0)