Note that there are some explanatory texts on larger screens.

plurals
  1. POstrange behavior reading a file
    primarykey
    data
    text
    <p>I am writing a program in Haskell here it is the code</p> <pre><code>module Main where import IO import Maybe import Control.Monad.Reader --il mio environment consiste in una lista di tuple/coppie chiave-valore data Environment = Env {variables::[(String,String)]}deriving (Show) fromEnvToPair :: Environment-&gt; [(String,String)] fromEnvToPair (Env e)= e estrai' x d |length x==0=[] |otherwise=estrai x d estrai (x:xs) d | (x:xs)=="" =[] | x== d=[] | otherwise = x:(estrai xs d) --estrae da una stringa tutti i caratteri saino a d conta' x d n | length x==0 = 0 |otherwise = conta x d n conta (x:xs) d n | x== d=n | otherwise = (conta xs d (n+1)) primo (a,b,c)=a secondo (a,b,c)=b terzo (a,b,c)=c estraifrom x d n |n&gt;=(length x) =[] | x!!n==d = [] |otherwise = x!!n:(estraifrom x d (n+1)) readerContent :: Reader Environment Environment readerContent =do content &lt;- ask return ( content) -- resolve a template into a string resolve :: [Char]-&gt; Reader Environment (String) resolve key= do varValue &lt;- asks (lookupVar key) return $ maybe "" id varValue maketuple x =(k,v,l) where k= (estrai' x ':')--usare estrai' v=estraifrom x ';' (conta' x ':' 1) l= (length k)+(length v)+2 --è l'offset dovuto al; e al : makecontext x | length x==0 = [] | (elem ':' x)&amp;&amp;(elem ';' x)==False = [] |otherwise= (k,v):makecontext (drop l x) where t= maketuple x k= primo t v= secondo t l= terzo t doRead filename = do bracket(openFile filename ReadMode) hClose(\h -&gt; do contents &lt;- hGetContents h return contents let cont=makecontext contents putStrLn (take 100 contents) return (contents)) -- putStrLn (snd (cont!!1))) -- putStrLn (take 100 contents)) -- estrae i caratteri di una stringa dall'inizio fino al carattere di controllo -- aggiungere parametri to the environment -- estrae i caratteri di una stringa dall'inizio fino al carattere di controllo -- aggiungere parametri to the environment -- lookup a variable from the environment lookupVar :: [Char] -&gt; Environment -&gt; Maybe String lookupVar name env = lookup name (variables env) lookup' x t=[v| (k,v)&lt;-t,k==x] fromJust' :: Maybe a -&gt; a fromJust' (Just x) = x fromJust' Nothing = error "fromJust: Nothing" main = do file&lt;- doRead "context.txt"-- leggo il contesto let env= Env( makecontext file) -- lo converto in Environment let c1= fromEnvToPair(runReader readerContent env) putStrLn(fromJust'(lookupVar "user" env)) --putStrLn ((lookup' "user" (fromEnvToPair env))!!0)-- read the environment --putStrLn ("user"++ (fst (c1!!1))) putStrLn ("finito") --putStrLn("contesto" ++ (snd(context!!1))) </code></pre> <p>What I want to do is reading a file formating the content and puting it in Environment, well it read the file and does all the other stuff only if in doRead there is the line putStrLn (take 100 contents) otherwise I can not take anithing, somebody knows why? I do not want to leave that line if I do not know why thanks in advance thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload