Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

01/1 - Idris#20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
appositum merged 1 commit intounleashed-coding:masterfromappositum:master
Dec 2, 2018
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions2018/01_1/idris/appositum.idr
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
import Data.String

subtract : Neg a => a -> a -> a
subtract x y = y - x

parse : List Char -> Integer -> Integer
parse (x::xs) =
case parseInteger (pack xs) of
Nothing => id
Just num =>
case x of
'+' => (+num)
'-' => subtract num

loop : Integer -> List (List Char) -> Integer
loop acc lst = foldl (\x, f => f x) acc (map parse lst)

main : IO ()
main = do
args <- getArgs
case args of
(_::arg::_) => do
file <- readFile arg
case file of
Right res => print $ loop 0 $ map unpack (lines res)
Left _ => putStrLn "File not found"
_ => putStrLn "Usage: ./appositum input.txt"

[8]ページ先頭

©2009-2025 Movatter.jp