基于var的更改值
我正在尝试从文件(Integer,char ...)中读取一种类型的输入,并根据类型文件读取值。
我的问题是我的输入是整数我必须要 让Value = read contents :: int
如果我的输入是char let value = read read contents :: string
我的处理方式是使用两个不同的文件,我已经试图实施几个条款,但到目前为止什么都没有。我能做的最好的方法是什么?
import System.Environment
import System.IO
import Data.List
import Data.Typeable
---------------------------
{ HASKELL CODE } (problem:)
---------------------------
main :: IO()
main = do
args <- getArgs
contents <- readFile (head args)
let var = (show (typeOf contents))
if var == "[Char]" then
let value = read contents::String
else if var == "[Int]"
let value = read contents::Int
else
putStrLn "test"
print(problem value)
I'm trying to read a type of input from a file (Integer, Char...), and let the value depending on the type file.
My problem is if my input is an Integer i have tolet value = read contents::Int
if my input is Char let value = read contents::String
the way im dealing with this is using two different files, i've tried to implement several if clauses but nothing worked so far. whats the best way i can do to approach this?
import System.Environment
import System.IO
import Data.List
import Data.Typeable
---------------------------
{ HASKELL CODE } (problem:)
---------------------------
main :: IO()
main = do
args <- getArgs
contents <- readFile (head args)
let var = (show (typeOf contents))
if var == "[Char]" then
let value = read contents::String
else if var == "[Int]"
let value = read contents::Int
else
putStrLn "test"
print(problem value)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用
:
您可以进行辩护:
One way is to use
Either
:You could deforest: