Giter Club home page Giter Club logo

Comments (45)

zonyitoo avatar zonyitoo commented on September 28, 2024

How about status of this issue?

from fcore.

bixuanzju avatar bixuanzju commented on September 28, 2024

@zonyitoo Won't be implemented any time sooner.

from fcore.

bixuanzju avatar bixuanzju commented on September 28, 2024

@lihuanglx So this is done?

from fcore.

brunocdsoliveira avatar brunocdsoliveira commented on September 28, 2024

There is a difference between infix operators and been anle to use prefix functions as infix functions. I believe Huang implemented the later, bit not the former.

from fcore.

bixuanzju avatar bixuanzju commented on September 28, 2024

Alright, so

  • Using prefix functions with infix notation, e.g.,

    1 `add` 2
  • Using infix functions with prefix notation, e.g.,

    (+) 1 2

from fcore.

brunocdsoliveira avatar brunocdsoliveira commented on September 28, 2024

Well, what I meant was, being able to define infix operators, such as:

(+++) :: [a] -> [a] -> [a]

in Haskell. Which then you can use as:

[1,2] +++ [3,4]

I believe this is also what @zonyitoo meant.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@brunocdsoliveira Yes, exactly.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx Seems it does not work with type parameters

-- ADT List
data PList[A] = Nil
              | Cons A (PList[A])
              ;

let cons[A] (v : A) (l : PList[A]) : PList[A] =
    Cons[A] v l;

1 `cons[Int]` (Nil[Int])

And it also failed to handle this case

let add (v : Int) (a : Int) (b : Int) : Int =
    v + a + b;

1 `add 2` 3
      ^~~~ Lexical Error

from fcore.

wxzh avatar wxzh commented on September 28, 2024
  1. Define something like let conInt = cons[Int] will avoid the problem
  2. Application inside backquote is not allowed, even in Haskell

BTW, cons (and length, nil ...) has been occupied as a keyword. @zonyitoo

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@wxzh Alright. Then the second one should not be allowed.

The first case should be supported.

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024

@zonyitoo Type parameters supported.

let theSecond[A,B] (a:A) (b:B) = b;

1 `theSecond[Int,String]` "abc"                             ===> "abc"

1 `theSecond[Int,String]` "abc" `theSecond[String,Int]` 6   ===> "6"

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024

Sorry.. misclicked

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx excellent

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024
let (++) (x:String) (y:String) : String = x.concat(y);

"ab" ++ "cd" 

Or regard (++) as a normal function as below.

let (++) (x:String) (y:String) : String = x.concat(y)
and gao (f:String->String->String) (a:String) (b:String) : String = f a b;

gao (++) "ab" "cd"

(++) "ab" "cd"

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx Is that work now? Here is a parse error

let (:)[A] (a : A) (l : PolyList[A]) = Cons[A] a l;

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx how to call this function

let (++)[A] (a : PolyList[A]) (b : PolyList[A]) : PolyList[A] = ...

how to apply the type parameter??

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024

@zonyitoo

  1. Only !#$%&*+./<=>?@\^|-~ supported, please try another symbol instead :.
  2. Just like a normal function, list1 ++[Int] list2.The type inference is not strong enough now, so it needs explicit type notation -_-||.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx alright, sounds reasonable. ;)

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx i can't define an operator named <+> or <|>? They are in your supported list.

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024
let (<+>) [A] (a : A) (b: A) = a;
1 <+> 2

Maybe you forgot the parentheses?

Like Haskell, it requires parentheses in the definition.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx Ah!!! Stupid mistake! Thanks!!!

from fcore.

bixuanzju avatar bixuanzju commented on September 28, 2024

@lihuanglx Do you consider this feature fully implemented?

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024

@bixuanzju Yes, it should be closed now.

from fcore.

brunocdsoliveira avatar brunocdsoliveira commented on September 28, 2024

@lihuanglx Do you allow infixity declarations for the operators, as in Haskell?

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024

@brunocdsoliveira

Sorry, I didn't take that into consideration. I'll improve it.

The new goal is to allow:

let a <+> b = a + b
let a `add` b = a + b

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx How about associativity?

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024

@zonyitoo All user defined operators have left associativity and the highest precedence.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx it would be better if operators could supports right associativity, or you will have to add brackets around them.

from fcore.

lihuanglx avatar lihuanglx commented on September 28, 2024

@zonyitoo Thanks, I'll consider that.

from fcore.

bixuanzju avatar bixuanzju commented on September 28, 2024

@zonyitoo @lihuanglx In Haskell, you can define the associativity, say

infixr 9 <+>

I don't know if it's easy to implement in our language. Since most operators are left associative, it's reasonable to use it as default.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@bixuanzju I agree with making left associativity as default, but some of the operators have to be right associative. Such as : in Haskell, or the magical $ operator in Haskell.

from fcore.

brunocdsoliveira avatar brunocdsoliveira commented on September 28, 2024

@lihuanglx what I suggested above was to allow infixity declarations, such as the one Jeremy has shown:

infixr 9 <+>

so that the default settings can be overriden. This may require some more work.

I didn't mean to allow this:

let a `add` b = a + b

This does not seem helpful to me.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@lihuanglx Should this situation be allowed in F2J?

data Doc = Text String
         | Line Int
         | String `Text` Doc;

Also, I cannot use the constructor of data in infixop.

from fcore.

zhiyuanshi avatar zhiyuanshi commented on September 28, 2024

@zonyitoo As to the first issue, I don't think so.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@zhiyuanshi Why? Seems Haskell supports that.

from fcore.

bixuanzju avatar bixuanzju commented on September 28, 2024

@zonyitoo You can't define a datatype like this, you have two constructors, both named Text

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@bixuanzju @zhiyuanshi Ahhhh, alright, that's a bad example...

from fcore.

bixuanzju avatar bixuanzju commented on September 28, 2024

@zonyitoo Data constructors can't be used in infixop, that's true

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

I think I should invite @Demonsu to demonstrate the problem. I don't know the detail of his problem.

from fcore.

wxzh avatar wxzh commented on September 28, 2024

@zonyitoo Do you mean that you want something like "1 Cons Nil "? It should be valid. I think there is a missing case in the parser for it. @lihuanglx

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@wxzh Humph.. yes, this case should be valid. But should this case be valid?

data Doc = Text String
         | Line Int
         | String `Union` Doc;

from fcore.

wxzh avatar wxzh commented on September 28, 2024

@zonyitoo Yes, you can do this in Haskell. But why do you want to define it in this way? I don't see any benefits it brings.

from fcore.

zonyitoo avatar zonyitoo commented on September 28, 2024

@wxzh I don't know, is not me... I didn't use that in F2J, but I just curious about whether it should be included in F2J.

from fcore.

xiafan-su avatar xiafan-su commented on September 28, 2024

Sorry guys. Yesterday, I was not sure that my pretty printer lib can be implemented without infix constructors. Then I mentioned it with Elton. It seems can be replaced by prefix. And I just finish it in f2j.

from fcore.

wxzh avatar wxzh commented on September 28, 2024

@Demonsu It does not matter. You help us to find a bug in the Parser :). For now, you should always define functions and constructors in prefix annotation, but you can use them in infix annotation (after @lihuanglx fixes it).

from fcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.