
354 Mass. 670 (1968)
241 N.E.2d 845
EDWARD J. BEATON, petitioner.
Supreme Judicial Court of Massachusetts, Suffolk.
October 8, 1968.
November 5, 1968.
Present: WILKINS, C.J., SPALDING, WHITTEMORE, CUTTER, & REARDON, JJ.
Robert Emmet Dinsmore & Lester M. Gold for the petitioner.
Willie J. Davis, Assistant Attorney General, for the Superintendent Massachusetts Correctional Institution at Walpole & another.
SPALDING, J.
This is a petition for a writ of habeas corpus brought by a prisoner who is serving a sentence in the Massachusetts Correctional Institution at Walpole (Walpole).
The case was heard on the petition and a motion to dismiss. The facts alleged in the petition as amplified by facts agreed to by the parties are these.
*671 On June 16, 1961, the petitioner was convicted of the crime of robbery and was sentenced to serve five to seven years at Walpole. He was released on parole on January 6, 1964. On March 9, 1964, the parole was revoked and he was returned to Walpole on April 9. On May 17, 1965, the petitioner was again released on parole. On July 24, 1967, while on parole from Walpole, the petitioner was convicted of the crime of breaking and entering in the nighttime and larceny, and received a sentence of three to five years at Walpole, under which sentence he is presently confined.
On November 17, 1965, St. 1965, c. 764, was enacted; it became effective on February 15, 1966. This statute, which amends G.L.c. 127, § 133, provides, among other things, that a person who commits a crime while on parole shall not be eligible for parole on the subsequent sentence until he has served two thirds of the minimum sentence. Relying on this statute the Department of Correction has computed the petitioner's parole eligibility date for the subsequent offence as being July 23, 1969. Under the statute, prior to its amendment, the petitioner would have been eligible for parole in August of 1968.
The Commonwealth filed a motion to dismiss the petition on the ground that the petitioner had shown no ground for relief by habeas corpus. This was in effect a demurrer and we treat it as such. E.S. Parks Shellac Co. v. Jones, 265 Mass. 108, 110. The motion was "allowed without prejudice" on June 4, 1968. The petitioner appealed. G.L.c. 231, § 96.
At the time of its allowance, the petitioner, as the facts alleged, was not illegally detained at Walpole. Under the case pleaded by the petitioner, he would not have been even eligible for parole until August of 1968. The remedy of habeas corpus may be availed of as of right by one unlawfully imprisoned or restrained of his liberty. G.L.c. 248, § 1. See O'Leary, petitioner, 325 Mass. 179, 184; Chin Yow v. United States, 208 U.S. 8, 13. The writ also may be issued under G.L.c. 248, § 25, at the discretion of the court if it could order the petitioner to be discharged immediately. But *672 in this situation the petitioner was neither unlawfully imprisoned, nor entitled to an immediate discharge, nor even eligible for parole. The basis, therefore, for relief by habeas corpus was lacking, and the judge rightly ordered the petition dismissed.[1]
The case could very well end here. But as the parties desire an opinion on the constitutionality of St. 1965, c. 764, as interpreted by the Department of Correction, and have argued the question, we shall indicate our views. See Wellesley College v. Attorney Gen. 313 Mass. 722, 731; Vautier, petitioner, 340 Mass. 341, 344-345.
We now turn to the petitioner's contention that the interpretation placed on St. 1965, c. 764, by the Department of Correction was erroneous. Section 1 of that act amended G.L.c. 127, § 133, to provide in subsection (c) "that no prisoner held under a sentence containing a minimum sentence for a crime committed while on parole shall receive a parole permit until he shall have served two thirds of such minimum sentence...." Section 2 of that act, however, states that no part of § 133, as amended by § 1, shall apply "in the case of any person sentenced prior to the effective date of this act if application of the provisions thereof would have the effect of making his punishment more severe." The petitioner, who was sentenced for robbery and was paroled before the effective date, argues that the application of subsection (c) would make his punishment more severe by increasing the period he must serve before being eligible for parole. Under the petitioner's interpretation, subsection (c) would apply to prisoners sentenced before the effective date of the act only if they were not paroled until after that date. In other words, if both the prior sentence and parole occurred before that date, as was the case here, the provisions of subsection (c) do not apply. We disagree with this interpretation.
*673 The petitioner erroneously assumes that the phrase "would have the effect of making his punishment more severe" could apply to a sentence received for a crime committed after the act's effective date. We reject that assumption. In the petitioner's case, the word "punishment" refers only to his sentence for the 1961 robbery conviction; it does not refer to any punishment he received after the effective date of the act. Since the statute did not increase the punishment for the robbery, § 2 is not relevant in this case, and subsection (c) controls the petitioner's eligibility date.
The petitioner argues that such an interpretation gives no effect to § 2. This is incorrect, as can be seen by a comparison of the prior G.L.c. 127, § 133, as appearing in St. 1955, c. 770, § 69, and § 1, which became the new § 133. Under the prior § 133, the prisoner generally had to serve at least two thirds of his minimum sentence before becoming eligible for parole. In contrast, subsection (b) of the new § 133 reduced this requirement to only one third. Other parts of the new § 133 appearing in § 1, however, increased the period a prisoner must serve before becoming eligible for parole; for example, subsection (a) established a minimum period of two years for certain crimes, whereas the minimum under the former § 133 had been only one year. It is in relation to such changes that § 2 applies; without such a provision, subsection (a) could modify to the prisoner's detriment his parole eligibility date for a sentence received before the act was passed.
The petitioner maintains that if subsection (c) applies to him it is unconstitutional as an ex post facto law, which the States are prohibited from passing by the United States Constitution, art. 1, § 10. See art. 24 of our Declaration of Rights. In his view, the statute is ex post facto because it increased the penalty for a crime committed while on parole, which he had obtained before the act was passed.
In the leading case of Calder v. Bull, 3 Dall. 396, the court listed the following four examples of ex post facto laws: "1st. Every law that makes an action done before the passing of the law, and which was innocent when done, criminal; *674 and punishes such action. 2d. Every law that aggravates a crime, or makes it greater than it was, when committed. 3d. Every law that changes the punishment, and inflicts a greater punishment, than the law annexed to the crime, when committed. 4th. Every law that alters the legal rules of evidence, and receives less, or different, testimony, than the law required at the time of commission of the offence, in order to convict the offender" (at 390). The third of the foregoing categories is the basis of the petitioner's attack on the statute.
In arguing that subsection (c) unconstitutionally increases his punishment, the petitioner relies heavily on the case of Greenfield v. Scafati, Superintendent, Mass. Correctional Inst., Walpole, 277 F. Supp. 644, affd. sub nom. Scafati, Correctional Superintendent, v. Greenfield, 390 U.S. 713. Greenfield had been sentenced in 1962. While he was imprisoned, G.L.c. 127, § 129, was amended in 1965 to provide for the forfeiture, if a parolee violated his parole and was returned to prison, of certain good conduct deductions, which previously had been available. The court held that the statute was unconstitutional as applied to persons such as Greenfield who had been sentenced but not paroled before § 129 was amended.
The present case, however, is distinguishable. The statute in the Greenfield case affected the deductions from a sentence that was imposed before the act's effective date. In contrast, subsection (c) does not affect the petitioner's sentence for his prior conviction of robbery. That section instead relates only to the parole eligibility date for sentences imposed after the statute became effective. Subsection (c) then is analogous to habitual offender statutes, which uniformly have been held constitutional even though one of the prior crimes was committed before the enactment of the statute. Gryger v. Burke, Warden, 334 U.S. 728. McDonald v. Massachusetts, 180 U.S. 311. Pettway v. United States, 216 F.2d 106 (6th Cir.). Wey Him Fong v. United States, 287 F.2d 525 (9th Cir.), cert. den. 366 U.S. 971. Oliver v. United States, 290 F.2d 255 (8th Cir.), cert. den. 368 U.S. 850. See United *675 States v. Heikkinen, 240 F.2d 94 (7th Cir.), reversed sub nom. Heikkinen v. United States on other grounds, 355 U.S. 273; Smith v. United States, 312 F.2d 119 (10th Cir.). Similarly, the fact that the petitioner's parole related to a conviction which occurred prior to the enactment of c. 764 does not make the act ex post facto when applied to a crime committed after the act became effective.[2] We conclude that c. 764 as interpreted by the Department did not offend against the ex post facto prohibition of the Constitution of the United States.
Order dismissing petition affirmed.
NOTES
[1]  Because of the limited nature of the remedy of habeas corpus, a more appropriate remedy would have been that afforded by our declaratory procedure. G.L.c. 231A. See Woods v. State Bd. of Parole, 351 Mass. 556, 559, and cases cited.
[2]  According to the petition and the facts agreed to by the parties it appears only that the petitioner was convicted after the effective date of the act. But the Commonwealth argues that the crime on which the conviction was based also was committed after the effective date of the statute. The petitioner does not contend otherwise. This fact is confirmed by the indictment under which the petitioner was convicted.
