[Soft] New Hopeless user exprience

English forum for http://www.nedopc.org/nedopc

Moderator: Shaos

DougT
Junior
Posts: 5
Joined: 02 Dec 2014 17:04
Location: 50.97.94.54

[Soft] New Hopeless user exprience

Post by DougT »

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
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Post by Shaos »

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?
Я тут за главного - если что шлите мыло на me собака shaos точка net
DougT
Junior
Posts: 5
Joined: 02 Dec 2014 17:04
Location: 50.97.94.54

Post by DougT »

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
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Post by Shaos »

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...
Я тут за главного - если что шлите мыло на me собака shaos точка net
DougT
Junior
Posts: 5
Joined: 02 Dec 2014 17:04
Location: 50.97.94.54

Post by DougT »

Yes, I used the version from GitHub. It is version Hopeless v0.6RC

-- Doug
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Post by Shaos »

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?
Я тут за главного - если что шлите мыло на me собака shaos точка net
DougT
Junior
Posts: 5
Joined: 02 Dec 2014 17:04
Location: 50.97.94.54

Post by DougT »

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
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Post by Shaos »

Ok, understood
Я тут за главного - если что шлите мыло на me собака shaos точка net
DougT
Junior
Posts: 5
Joined: 02 Dec 2014 17:04
Location: 50.97.94.54

Post by DougT »

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
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Post by Shaos »

This particular implementation is fully lazy as I know
Я тут за главного - если что шлите мыло на me собака shaos точка net