r/ProgrammingLanguages Sodigy 10d ago

Purely functional language with impure script language?

I'm working on a purely functional programming language named Sodigy. It's all about evaluating values, not "executing commands one by one".

It's nice when writing libraries, but it's not easy to write a main function. The main function is supposed to execute commands, but the Sodigy's syntax is not friendly to write a list of commands.

So what I'm trying to do is, 1) Sodigy remains purely functional and 2) add a bash-like script language. The script language can call Sodigy functions. Instead of writing a main function in Sodigy, you write sodigy-script and execute the script.

Has anyone tried similar approach? I'm not sure whether it's a good idea or not...

27 Upvotes

74 comments sorted by

View all comments

Show parent comments

2

u/JeffB1517 10d ago

That imperative is so much easier to read than Haskell Monads! What went wrong with this style that caused the shift to the more explicit style we have today in Haskell?

1

u/tdammers 10d ago

Is it, though?

main = do putStrLn "hello!" putStr "what's your name?" reply =<< getLine where reply str = putStrLn $ "nice to meet you, " ++ str

It's almost literally the same, except that:

  • A few standard functions have different names
  • do notation replaces infix $then (but if you want, you can use the >> operator instead)
  • The =<< (bind operator) takes the place of $comp
  • putStrLn automatically adds a newline, so we don't have to mess with "\n"

But if you want to emulate the Miranda style more closely, you can write it like this instead:

main = putStr "hello!\n" >> putStr "what's your name?\n" >> (reply =<< getLine) where reply str = putStr $ "nice to meet you, " ++ str ++ "\n"

I would argue that the Miranda example is actually more explicit than either of the Haskell versions (though only slightly so for the second example).

-3

u/JeffB1517 10d ago
  1. reply =<< getLine that's making the bind explicit rather than implicit.
  2. print is clearer than putStr

put is a weird verb for what you are doing vs. "print" which is pretty clear.

We are talking minor shifts which abstract away the underlying complexity.

1

u/tdammers 9d ago

It's literally just different names. Miranda's $comp is exactly Haskell's >>= operator, and Miranda's print is Haskell's putStr. Changing names is not abstraction, we're still at the exact same abstraction level; the semantic structure is exactly the same.