Jump to content
  • Advertisement
Sign in to follow this  
rholding2001

haskell and prolog

This topic is 4897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi there. i have to do an assignment in these two langiages, ive looked for the compilers and only found one for haskell the ghc or something, this however doesnt seem to work, ive installed it and when i run it a dos screen pops up and disapears immediatly. can any of you guys give me a definate link to a working compi;ler for both these langauges it will be greatly appreciated. i dont know anything about these things so i need direct help please thanks people

Share this post


Link to post
Share on other sites
Advertisement
What is probably happening is that you aren't providing the required parameters when you run your Haskell compiler, so the compiler issues an error message and exits. Because the compiler exits, the DOS window shuts and you don't get to read the error message.

Try running it in a dos window (Start menu->Run->"command"). Then the window won't close when the compiler does.

Here's the standard prolog interpreter.
http://www.swi-prolog.org/download.html

Share this post


Link to post
Share on other sites
hi ive just typed in what all the help files i have looked at claim are the way you state a function in haskell, the line was

testWord = "testing" and i get
:ERROR - Syntax error in input (unexpected `=')

how do i make testWord = "testing"?

i dont understand

Share this post


Link to post
Share on other sites
that is a correct haskell function, but you can't define functions in the interpreter. You need to create them in a file, and then load them.

foo.hs:

testWord :: String
testWord = "testing"

in hugs:
> :l foo.hs
> testWord
"testing"
>

(you don't have to define the types of functions, but it is good practice.)

/Nico

Share this post


Link to post
Share on other sites
Day 3 of learn haskell.

Ive looked at a load of tutorials and quite frankly im fed up of reversing strings and removing certain characters from them

What i need is to (ill explain this how i would in pascal, c or c++, i know haskel does not work like this)

i need to create a record that holds say a name ::string, age :: int, on/off :: bool

how do i store something like this and then use a function to get the name of the thing, its age and is it turned on or off.

how would i answer a question like. is archibold turned on?

thanks

Share this post


Link to post
Share on other sites
something like this, perhaps..


data Record = Record {
name :: String,
age :: Int,
onoff :: Bool}

myrecord = Record {
name = "Nico",
age = 666,
onoff = True}

myfunc :: Record -> String
myfunc rec = let r_name = name rec;
r_age = age rec;
r_onoff = onoff rec; in
"Name: " ++ r_name ++ "\nAge: " ++ (show r_age) ++ "\nOn: " ++ (show r_onoff)

just remember you can't have truly mutable varibles in haskell without monads.

hope it helps..
/Nico

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!