Showing posts with label Haskell 연습. Show all posts
Showing posts with label Haskell 연습. Show all posts

Wednesday, October 06, 2010

IO Int를 Int로 바꾸기.

RandomIO에서 나오는 int는 IO Int이다. 이를 Int로 변경해야 하는데...
다음의 방법이 있다.

ranNo <- randomIO

ranNo는 IO Int가 아닌 Int이다.
단점도 있다.

let ranNoTemp = randomIO
ranNo <- ranNoTemp

위의 경우 ranNoTemp는 IO Int이나, ranNoTEmp를 실행할 때마다 randomIO가 실행되어 난수가 갱신된다.
하지만, ranNo를 실행해도 난수는 재생성되지 않는다.

real world와 pure world의 의사소통의 단절때문인가...
혹시나 방법이 있나 하고 찾아보았더니, IO Int를 Int로 직접적으로 바꾸는 방법은 없다고 한다.

Sunday, September 26, 2010

File 내용의 추출

import List

main = do cs <- readFile "C:\\SPR.txt"
putStrLn $ myManupulation cs

myManupulation cs = lines cs !! 3


Thursday, September 23, 2010

File의 read-in

사정상 윈도우에서 작업중...
main = do x <- readFile "C:\\SPR.txt"
lines x를 통해서 배열로. 다시 배열을 가공하는 방법.