Comments (2)
и еще как превратить IO T.Text в T.Text ?
подозреваю, что ответ где-то рядом с "Если вы пишете чистую функцию, которую затем планируете использовать в блоке do, то можете использовать return (), " (нужен пример этой чистой функции, ведь return () - тип IO(). а нужно T.Text)
from hs2s-lab.
Нужно искать утечку.
Значение типа Data.Text внутри монады IO можно вытащить и работать с ним с помощью bind, тип которой Monad m => m a -> (a -> m b) -> m b:
import Data.Text.IO as T
main = T.readFile "/tmp/path/to/file" >>= \file -> {- тут у file тип Data.Text -} T.putStr file
Я об этом буду рассказывать на следующей лекции, если успею.
Или, если привычны императивные ЯП, с помощью do-нотации:
import Data.Text.IO as T
main = do
-- у функции readFile тип FilePath -> IO Data.Text
-- тип FilePath - синоним обычной строки
-- а вот у file будет тип просто Data.Text
file <- T.readFile "/tmp/path/to/file"
T.putStr file
-- фишка в том, что блок do должен вернуть значение монадического типа IO
-- и функция T.putStr как раз имеет тип Data.Text -> IO ()
-- если на экран ничего выводить не нужно, вместо последней строки можно просто написать return ()
from hs2s-lab.
Related Issues (8)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hs2s-lab.