view interps/rhotor/Misc.hs @ 12518:2d8fe55c6e65 draft default tip

<int-e> learn The password of the month is release incident pilot.
author HackEso <hackeso@esolangs.org>
date Sun, 03 Nov 2024 00:31:02 +0000
parents 859f9b4339e6
children
line wrap: on
line source

module Misc (
	stringToNodeTree,
	nodeTreeToString,
	numberToNodeTree,
	nodeTreeToNumber,
	apply
)
where

import Node


stringToNodeTree		:: String -> Node
stringToNodeTree ""		= Nil
stringToNodeTree (c:t)	= Cons (numberToNodeTree (fromEnum c)) (stringToNodeTree t)

nodeTreeToString			:: Node -> String
nodeTreeToString Nil		= ""
nodeTreeToString (Cons a b)	= (toEnum (nodeTreeToNumber a):nodeTreeToString b)

numberToNodeTree 		:: (Integral a) => a -> Node
numberToNodeTree 0		= Nil
numberToNodeTree (n+1) 	= Cons Nil (numberToNodeTree n)

nodeTreeToNumber				:: (Integral a) => Node -> a
nodeTreeToNumber Nil			= 0
nodeTreeToNumber (Cons Nil a)	= (nodeTreeToNumber a) + 1


apply		:: Node -> Node -> Node
apply a b	= (Application a b)