Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alex D
GHC
Commits
fa1e4ffe
Commit
fa1e4ffe
authored
Dec 09, 2008
by
dreixel
Browse files
Fix #2759: add ability to serialize Rational
parent
27992bf8
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/utils/Serialized.hs
View file @
fa1e4ffe
...
...
@@ -86,16 +86,16 @@ deserializeWithData' bytes = deserializeConstr bytes $ \constr_rep bytes ->
serializeConstr
::
ConstrRep
->
[
Word8
]
->
[
Word8
]
serializeConstr
(
AlgConstr
ix
)
=
serializeWord8
1
.
serializeInt
ix
serializeConstr
(
IntConstr
i
)
=
serializeWord8
2
.
serializeInteger
i
serializeConstr
(
FloatConstr
d
)
=
serializeWord8
3
.
serialize
Double
d
serializeConstr
(
FloatConstr
r
)
=
serializeWord8
3
.
serialize
Rational
r
serializeConstr
(
StringConstr
s
)
=
serializeWord8
4
.
serializeString
s
deserializeConstr
::
[
Word8
]
->
(
ConstrRep
->
[
Word8
]
->
a
)
->
a
deserializeConstr
bytes
k
=
deserializeWord8
bytes
$
\
constr_ix
bytes
->
case
constr_ix
of
1
->
deserializeInt
bytes
$
\
ix
->
k
(
AlgConstr
ix
)
2
->
deserializeInteger
bytes
$
\
i
->
k
(
IntConstr
i
)
3
->
deserialize
Double
bytes
$
\
d
->
k
(
FloatConstr
d
)
4
->
deserializeString
bytes
$
\
s
->
k
(
StringConstr
s
)
1
->
deserializeInt
bytes
$
\
ix
->
k
(
AlgConstr
ix
)
2
->
deserializeInteger
bytes
$
\
i
->
k
(
IntConstr
i
)
3
->
deserialize
Rational
bytes
$
\
r
->
k
(
FloatConstr
r
)
4
->
deserializeString
bytes
$
\
s
->
k
(
StringConstr
s
)
x
->
error
$
"deserializeConstr: unrecognised serialized constructor type "
++
show
x
++
" in context "
++
show
bytes
...
...
@@ -140,11 +140,11 @@ deserializeInt :: [Word8] -> (Int -> [Word8] -> a) -> a
deserializeInt
=
deserializeFixedWidthNum
serialize
Double
::
Double
->
[
Word8
]
->
[
Word8
]
serialize
Double
=
serializeString
.
show
serialize
Rational
::
(
Real
a
)
=>
a
->
[
Word8
]
->
[
Word8
]
serialize
Rational
=
serializeString
.
show
.
toRational
deserialize
Double
::
[
Word8
]
->
(
Double
->
[
Word8
]
->
a
)
->
a
deserialize
Double
bytes
k
=
deserializeString
bytes
(
k
.
read
)
deserialize
Rational
::
(
Fractional
a
)
=>
[
Word8
]
->
(
a
->
[
Word8
]
->
b
)
->
b
deserialize
Rational
bytes
k
=
deserializeString
bytes
(
k
.
fromRational
.
read
)
serializeInteger
::
Integer
->
[
Word8
]
->
[
Word8
]
...
...
@@ -171,4 +171,5 @@ deserializeList deserialize_element bytes k = deserializeInt bytes $ \len bytes
go
::
Int
->
[
Word8
]
->
([
a
]
->
[
Word8
]
->
b
)
->
b
go
len
bytes
k
|
len
<=
0
=
k
[]
bytes
|
otherwise
=
deserialize_element
bytes
(
\
elt
bytes
->
go
(
len
-
1
)
bytes
(
k
.
(
elt
:
)))
\ No newline at end of file
|
otherwise
=
deserialize_element
bytes
(
\
elt
bytes
->
go
(
len
-
1
)
bytes
(
k
.
(
elt
:
)))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment