Commit 869a14e5 authored by Mart Lubbers's avatar Mart Lubbers

add generic instances for Integer

parent 5021fdcc
Pipeline #40616 passed with stage
in 2 minutes and 2 seconds
......@@ -3,6 +3,9 @@
/// Ported from the Haskell frontend by Tim Steenvoorden
definition module Data.Integer
from Data.GenDefault import generic gDefault
from Data.GenLexOrd import generic gLexOrd, :: LexOrd
from Data.GenEq import generic gEq
import StdOverloaded
:: Integer = {integer_s ::!Int, integer_a ::!.{#Int}};
......@@ -43,3 +46,7 @@ instance toInteger String
/*
integer_a_to_double :: !Int !{#Int} -> Real
*/
derive gEq Integer
derive gLexOrd Integer
derive gDefault Integer
......@@ -2,6 +2,10 @@ implementation module Data.Integer
import StdEnv
import Data.Integer.ToString, Data.Integer.ToInteger, Data.Integer.Add, Data.Integer.Mul,Data.Integer.Div
import Data.GenDefault
import Data.GenLexOrd
import qualified Data.GenLexOrd
import Data.GenEq
instance toChar Integer where
toChar i = toChar (toInt i)
......@@ -1127,3 +1131,10 @@ rest_all_zeros i a
= True
*/
gEq{|Integer|} x y = x == y
gLexOrd{|Integer|} x y
| x == y = 'Data.GenLexOrd'.EQ
| x < y = 'Data.GenLexOrd'.LT
= 'Data.GenLexOrd'.GT
gDefault{|Integer|} = {integer_s=0, integer_a={}}
definition module Data.Integer.GenJSON
from Data.Maybe import :: Maybe
from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
from Data.Integer import :: Integer
derive JSONEncode Integer
derive JSONDecode Integer
implementation module Data.Integer.GenJSON
import StdEnv
import Data.Integer, Text.GenJSON
JSONEncode{|Integer|} _ i = [JSONInt i.integer_s, JSONArray [JSONInt c\\c<-:i.integer_a]]
JSONDecode{|Integer|} _ l=:[JSONInt s,JSONArray a:rest]
| not (all (\x->x=:(JSONInt _)) a) = (Nothing, l)
= (Just {integer_s=s, integer_a={c\\JSONInt c<-a}}, rest)
JSONDecode{|Integer|} _ l = (Nothing, l)
......@@ -114,6 +114,7 @@ import qualified Data.IntSet
import qualified Data.IntSet.Base
import qualified Data.Int
import qualified Data.Integer
import qualified Data.Integer.GenJSON
import qualified Data.Integer.Add
import qualified Data.Integer.Div
import qualified Data.Integer.Mul
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment