Commit 209b49f4 authored by Camil Staps's avatar Camil Staps 🚀

Merge branch 'generic-Integer' into 'master'

add generic instances for Integer

See merge request !313
parents 5021fdcc c89a2e35
Pipeline #40623 passed with stage
in 1 minute and 57 seconds
......@@ -4,6 +4,9 @@
definition module Data.Integer
import StdOverloaded
from Data.GenDefault import generic gDefault
from Data.GenEq import generic gEq
from Data.GenLexOrd import generic gLexOrd, :: LexOrd
:: Integer = {integer_s ::!Int, integer_a ::!.{#Int}};
......@@ -43,3 +46,7 @@ instance toInteger String
/*
integer_a_to_double :: !Int !{#Int} -> Real
*/
derive gDefault Integer
derive gEq Integer
derive gLexOrd 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,12 @@ rest_all_zeros i a
= True
*/
gDefault{|Integer|} = {integer_s=0, integer_a={}}
gEq{|Integer|} x y = x == y
gLexOrd{|Integer|} x y
| x == y = 'Data.GenLexOrd'.EQ
| x < y = 'Data.GenLexOrd'.LT
| otherwise = 'Data.GenLexOrd'.GT
definition module Data.Integer.GenJSON
from StdMaybe import :: Maybe
from Data.Integer import :: Integer
from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
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)
......@@ -116,6 +116,7 @@ import qualified Data.Int
import qualified Data.Integer
import qualified Data.Integer.Add
import qualified Data.Integer.Div
import qualified Data.Integer.GenJSON
import qualified Data.Integer.Mul
import qualified Data.Integer.ToInteger
import qualified Data.Integer.ToString
......
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