Skip to content

Instantly share code, notes, and snippets.

@OsePedro
Last active March 26, 2024 19:03
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 OsePedro/b0a1199b2fc5a70ce9281ab53e6c36f1 to your computer and use it in GitHub Desktop.
Save OsePedro/b0a1199b2fc5a70ce9281ab53e6c36f1 to your computer and use it in GitHub Desktop.
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
import System.Exit
newtype MyWord = MyWord Word deriving(Enum,Eq,Integral,Num,Ord,Real)
myInt :: MyWord -> Int
myInt = fromIntegral
{-# INLINE myInt #-}
fromMyWord :: Num a => MyWord -> a
fromMyWord (MyWord w) = fromIntegral w
{-# INLINE fromMyWord #-}
myInt2 :: MyWord -> Int
myInt2 = fromMyWord
int :: Word -> Int
int = fromIntegral
fib :: Integral a => a -> a
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
main = exitWith $ ExitFailure $ myInt (fib 10) + myInt2 (fib 10) + int (fib 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment