This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sensible | |
( foo | |
, bar | |
, Baz (..) | |
, Silly.okName | |
) | |
import Very.Silly.Named.Module as Silly | |
foo = Silly.longFooName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Foo.Bar as FB | |
import Baz | |
( foo | |
, fooBar | |
, fooBarBaz | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo = map . bar baz | |
where | |
bar = ... | |
baz = ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
runInstruction :: Intcode -> Prog Intcode | |
runInstruction ic = do | |
opcodes <- currentOpCode ic | |
case opcodes of | |
(One, m1, m2, m3) -> do | |
newIc <- op1 m1 m2 m3 (ip ic) (code ic) | |
return $ moveIp 4 . updateCode newIc $ ic | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(!!!) :: Integral a => MonadFail m => [a] -> Int -> m a | |
infixl 9 !!! | |
xs !!! i | |
| i < 0 = fail $ "index " ++ show i ++ " less that zero" | |
| i >= length xs = return 0 | |
| otherwise = return $ xs !! i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(!!!) :: Integral a => [a] -> Int -> Maybe a | |
infixl 9 !!! | |
xs !!! i | |
| i < 0 = Nothing | |
| i >= length xs = Just 0 | |
| otherwise = Just $ xs !! i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance Functor Prog where | |
fmap _ (Crashed e) = Crashed e | |
fmap f (End a) = End (f a) | |
fmap f (Running a) = Running (f a) | |
fmap f (AwaitInput a) = AwaitInput (f a) | |
instance Applicative Prog where | |
pure = Running | |
_ <*> (Crashed e) = Crashed e | |
(End f) <*> prog = fmap f prog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Applicative m => Monad m where | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance Monad Prog where | |
return = Running | |
(Crashed e) >>= _ = (Crashed e) | |
(End prog) >>= k = k prog | |
(Running prog) >>= k = k prog | |
(AwaitInput prog) >>= k = k prog | |
instance MonadFail Prog where | |
fail = Crashed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Prog a = Running a | AwaitInput a | End a | Crashed String deriving(Show, Eq) | |
data Intcode = Intcode { | |
input::[Int], | |
code::[Int], | |
-- ip: Instruction Pointer | |
ip::Int, | |
-- rb: Relative Base | |
rb::Int, | |
output::[Int] |
NewerOlder