Haskell IO: convert IO String to “Other type”

前端 未结 2 1334
孤独总比滥情好
孤独总比滥情好 2021-01-21 03:15

I have a Haskell program which takes a file as an input and convert it into a binary search tree.

import System.IO    

data Tree a = EmptyBST | Node a (Tree a)          


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 04:00

    You can't really escape the IO monad (except through unsafe functions) but there's no actual need to do that in your case:

    main = do f <- fileRead
              let newtree = ins 5 f
              putStr $ show newtree
    

    (live demo: here)

提交回复
热议问题