Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LightAndLight/5db01462ff3af1845f94f70a9ca59765 to your computer and use it in GitHub Desktop.
Save LightAndLight/5db01462ff3af1845f94f70a9ca59765 to your computer and use it in GitHub Desktop.
test :: Prism Integer [Digit]
test = prism' (snd . digitsToInt) intToDigits
where
digitsToInt :: [Digit] -> (Int, Int)
digitsToInt [] = (0, 0)
digitsToInt (d:ds) =
let (count, res) = digitsToInt ds
in (count+1, 10 ^ count * digitToInt d)
intToDigits :: Int -> Maybe [Digit]
intToDigits n
| n < 0 = Nothing
| otherwise =
liftA2 (++)
(intToDigits $ n `div` 10)
[unsafeIntToDigit $ n `rem` 10]
-- Single digit Int to Digit
unsafeIntToDigit :: Int -> Digit
unsafeIntToDigit = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment