nedoPC.org

Electronics hobbyists community established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 28 Mar 2024 15:14



Reply to topic  [ 10 posts ] 
[Soft] New Hopeless user exprience 
Author Message
Junior

Joined: 02 Dec 2014 17:04
Posts: 5
Location: 50.97.94.54
Reply with quote
I am enjoying hopeless quite a bit. My main documentation is from the book "Functional Programming" by Field and Harrison. I have ordered a used copy of "Functional Programming with Hope" by Bailey. I mainly use F# on Ubuntu and some Haskell. I like the small size of hopeless, the source code, and the quick compilation of hopeless.

Several things that I have noticed (Which I have communicated to Alexander):

1. The text uses named arguments (such as a name for a list pattern), which is not in hopeless.
2. I cannot enter a negative number such as -3, I have to use 0-3;
3. If numbers are set to longs, there is no abs function (not a big deal).
4. Some functions like map have a different syntax than the text. I will document this more fully at a later time.
5. It would be very nice to have the capability to retrieve the last command and edit it (a getline capability).

My biggest project (not very big) is a rational data type with associated functions. When I create a rational number (syntax r(n,d), n is the numerator, d the denominator, both numbers), I would like to be able to get it a "normal" form: remove the gcd from both n and d, and put the sign in the numerator. This does not seem possible on data creation, but a later function call is needed to perform this.

Regards,
Doug


02 Dec 2014 17:32
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
Thanks Doug! I'm also a little confused by new map definition and foldr instead of reduce, but it most likely will stay like this because I don't want to touch original Hope libraries. All other things I agree to fix sooner or later - especially last command functionality ( it's 1st item on my ToDo list on hopelog.com ).

P.S. What do you mean by setting numbers to longs? Removing REALS macrodefinition from num.h and recompiling?

_________________
:dj: https://mastodon.social/@Shaos


02 Dec 2014 17:55
Profile WWW
Junior

Joined: 02 Dec 2014 17:04
Posts: 5
Location: 50.97.94.54
Reply with quote
Post 
Yes, by "setting numbers to longs", I really mean removing the REAL definition and recompiling.

How difficult is it to fix the creation of negative number problem?

Regards,
Doug


03 Dec 2014 06:06
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
Do you use version from GitHub? I can try to fix it there first (before actual releasing of next version of Hopeless).

P.S. In this implementation unary + and - can not be declared, because binary + and - have the same name, and in the same time based on parsing source code any number must start with digit, so I can try to fix negative numbers by checking for '-' as possible start of a number (and probably '+') during parsing...

_________________
:dj: https://mastodon.social/@Shaos


03 Dec 2014 09:11
Profile WWW
Junior

Joined: 02 Dec 2014 17:04
Posts: 5
Location: 50.97.94.54
Reply with quote
Post 
Yes, I used the version from GitHub. It is version Hopeless v0.6RC

-- Doug


03 Dec 2014 21:49
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
DougT wrote:
Yes, I used the version from GitHub. It is version Hopeless v0.6RC

-- Doug


Ok, I see, thanks

Also in order to implement last command (and probably syntax highlighting) I should switch to ncurses (I'll make it optional) - you need arrows up/down to work as history scroll, right?

_________________
:dj: https://mastodon.social/@Shaos


03 Dec 2014 22:25
Profile WWW
Junior

Joined: 02 Dec 2014 17:04
Posts: 5
Location: 50.97.94.54
Reply with quote
Post 
Hello,

In fsi, the interactive F#, the up/down arrow keys access the interactive command history. Once the desired command is located, it can be edited by using the left and right arrow keys to place the cursor at the desired position. If you type at the cursor, new text is inserted, and if you press the Delete key, the current character is deleted.

-- Doug


04 Dec 2014 19:48
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
Ok, understood

_________________
:dj: https://mastodon.social/@Shaos


04 Dec 2014 20:50
Profile WWW
Junior

Joined: 02 Dec 2014 17:04
Posts: 5
Location: 50.97.94.54
Reply with quote
Post 
Concerning our discussion about hopeless being a lazy language:

It is lazy with respect to evaluating arguments to a function (evaluating by need), but it is not lazy with a function like

! infinite list
dec from : num -> list(num);
--- from n <= n :: from(n+1);

if you execute from(1), you need a CTRL-C to stop it. The book by Bailey discusses a lazy cons operator ::: in a version of Hope that would make the above lazy.


If you execute lcons(10,0,from(1)), you will get the list 0 thru 9.

! lazy cons
dec lcons: num # num # list(num) -> list(num);
--- lcons (0,num,(h::t)) <= [];
--- lcons (cnt, num,(h::t)) <= num :: lcons(cnt-1,h,t);

Hopeless behaves just like Haskell with respect to lazyness.

-- Doug


22 Dec 2014 15:46
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Post 
This particular implementation is fully lazy as I know

_________________
:dj: https://mastodon.social/@Shaos


27 Dec 2014 19:33
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.