Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell二维字符数组_Haskell - Fatal编程技术网

Haskell二维字符数组

Haskell二维字符数组,haskell,Haskell,我有与问题相关的Haskell语言。我需要在2D数组中存储大量字符。我如何存储它?我在文本文件中有10 X 10格式的字符,我想用Haskell语言将其存储在2D字符数组中。请尽快帮助我..谢谢 这是我尝试的代码,在这段代码中,我试图将x的值存储在名为listofchar的列表中: module TreasureFile where import System.IO main = do hdl <- openFile "map.txt" ReadMode rea

我有与问题相关的Haskell语言。我需要在2D数组中存储大量字符。我如何存储它?我在文本文件中有10 X 10格式的字符,我想用Haskell语言将其存储在2D字符数组中。请尽快帮助我..谢谢

这是我尝试的代码,在这段代码中,我试图将x的值存储在名为listofchar的列表中:

module TreasureFile where
import System.IO  


main =  do 
    hdl <- openFile "map.txt" ReadMode
    readbychar hdl

readbychar hdl =  do  
                  t <- hIsEOF hdl
                  if t 
                    then return()                     
                    else do
                      let listofchar=[] 
                      x <- hGetChar hdl
                      if x =='\n' 
                        then putChar '!'--return()
                        else listofchar x
                      readbychar hdl
模块文件,其中
导入系统.IO
main=do
hdl试试这个:

import System.IO

main = do
  textContents <- readFile "map.txt"
  let map = format textContents
  print $ map

format text = lines text
这是一种合成糖,用于:

[['a','a','a',..],['b','b','b',..],..] -- looks more like a map now

我在尝试时遇到此错误…找不到模块
Data.List.Split“它是隐藏包的成员
Split-0.2.2”。也许您需要在.cabal文件中的构建依赖项中添加'split'。使用-v查看搜索的文件列表。
[['a','a','a',..],['b','b','b',..],..] -- looks more like a map now