Hello, I’m new to Haskell and am attempting to write a seemingly impossible functional program incorporating the omniscience principle, a generic convergent sequence, and a type of cantor set 2^N
Q = set.empty
cycle take Q (iterate(set.Q))
N:Q
i:Q
k:Q
v:Q
n:Q
y = 0
cycle take y (iterate(+1))
z = any(y)
i = i index z
k = k indez z
v = v index z
v = v index z
n = n index z
Ninf = N index inf
N = N
X = 0
X = X + 1
l = set((v index n) SuchThat v index n elem set(empty, set()) :: n elem N)
x = Ninf == set(k elem l SuchThat all(i) elem N(k index i >= k index next i))
p = any(x) elem X(p(x) == 0) || all(x) elem X(p(x) == 1)
take f != "" (repeat)
take 100 (repeat)
take j (iterate(+1))
f = ""
a = chr j
if p == 1
then f++a
else
then f=f
prelude> f
so far I’ve read a book on Haskell, but I’m having problems, supposedly with parsing…
if anyone can fix this code have at it, but please get back to me!
when I look at the examples all the functions require lists…
how do I use a function for boolean values of its parameters as relates to other uses of said values
I think there’s no point in trying to brute-force figure out Haskell works. If you read beginner-level educational material you’ll have better results faster.
The problem with writing if p == 1 is that it isn’t a complete if expression. For it to be valid you must write if p == 1 then ... else ....
You can read about if more here: Starting Out - Learn You a Haskell for Great Good!
doubleSmallNumber x = if x > 100
then x
else x*2
From Learn You a Haskell for Great Good!:
Right here we introduced Haskell’s if statement. You’re probably familiar with if statements from other languages. The difference between Haskell’s if statement and if statements in imperative languages is that the else part is mandatory in Haskell. In imperative languages you can just skip a couple of steps if the condition isn’t satisfied but in Haskell every expression and function must return something. We could have also written that if statement in one line but I find this way more readable. Another thing about the if statement in Haskell is that it is an expression. An expression is basically a piece of code that returns a value. 5 is an expression because it returns 5, 4 + 8 is an expression, x + y is an expression because it returns the sum of x and y. Because the else is mandatory, an if statement will always return something and that’s why it’s an expression.
There are a few strange things in that snippet alone:
that last then should be removed, it should just be if ... then ... else ...
f ++ a should probably be changed to f ++ [a]
f=f is not an expression, you can only use this notation when binding things at the top level, with let, or with where. And even there it would mean "define a new variable f which is equal to itself recursively. When trying to evaluate it you would end up in an infinite loop.
Also note that in Haskell all variables are immutable, so f ++ [a] won’t change f itself, it will just return the result as a new value.
Seconding what romes said, you are better off spending your time learning Haskell than just writing something you think looks like Haskell and asking other people to fix it for you. You said “so far I’ve read a book on Haskell”, and I am not sure I believe that, maybe you mean that you’ve looked over a book and think you got the gist of the language, but the amount of syntax and type errors in your code makes me believe you didn’t really spend that much time learning the language itself. Which is fine, everyone has to learn at some point, and right now seems like that point for you. There are dozens of great books and free online tutorials and videos which you should spend some real time with in order to learn the language before you try to write something like this.