Question

I need your help please, my question is,

How i can make like this in haskell:

dim myVar = "text 1"

myVar += " and " + "text 2" 
Was it helpful?

Solution

The first thing you need to understand about Haskell is that you don't have variables, you only have values bound to names. Variables don't exists because values are immutable. This means that they never change. To change them is a compile time error.

At first this seems like a huge disadvantage, but in time you'll come to find that in most cases you don't need mutable values (and there are ways to do mutable values, but that's an advanced topic).

So, how would you write a function to do this? You could put in a file these contents:

module Main where

appendText :: String -> String -- Takes a string, returns a string
appendText text = text ++ " and " ++ "text 2"

main :: IO () -- An IO action with no result (think none or null)
main = do
    let myText = "text 1"
    putStrLn (appendText myText)

Since it seems that you have not yet introduced yourself fully to Haskell, I would recommend Learn You a Haskell, my favorite tutorial for the language. It starts with the very basics and works it way up to fairly advanced topics.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top