-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[email protected] #232
[email protected] #232
Conversation
b3d6c3f
to
8adf925
Compare
I added |
8adf925
to
b2c2a11
Compare
acfe6fa
to
9c421cc
Compare
9c421cc
to
a4f2c43
Compare
a4f2c43
to
346ef94
Compare
4e22761
to
89f3a75
Compare
5790ed7
to
a367dd0
Compare
6d72f19
to
472eecd
Compare
4567a75
to
fd83fe1
Compare
1301d5b
to
4f849d6
Compare
0e29d81
to
836c8e3
Compare
@@ -11,6 +11,7 @@ describe('on', function() { | |||
it('is a quaternary function', function() { | |||
eq(typeof S.on, 'function'); | |||
eq(S.on.length, 4); | |||
eq(S.on.toString(), 'on :: (b -> b -> c) -> (a -> b) -> a -> a -> c'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's exciting to be able to express the types of functions such as this one, @Bradcomp. :)
var dependencies = ['sanctuary-type-classes', 'sanctuary-def']; | ||
|
||
eq(dependencies.slice().sort(), | ||
Object.keys(require('./package.json').dependencies).sort()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea this is probably the better way now that I think about it, just having a test check if things are out of sync.
👍
//. makes it possible to write safe code without null checks. | ||
//. Sanctuary is a functional programming library inspired by Haskell | ||
//. and PureScript. It's stricter and more opinionated than [Ramda][]. | ||
//. Sanctuary makes it possible to write safe code without null checks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidchambers looks good, but maybe we should mention that Sanctuary can/should be used as an alternative to Ramda. On the top of my head: "It includes much the same functionality as Ramda, but is stricter and more opinionated."
I think this would make it more clear what functionality people can expect from Sanctuary ("write safe code without null checks" can be a bit vague). Most likely developers diving into functional programming in javascript will take a look at both Ramda and Sanctuary and I think a wording along these lines would make the relationship between them clear.
Just my 2 cents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. I'll make the change you have proposed.
When Sanctuary first came into existence it was focused on avoiding the null checks which several Ramda functions require. Sanctuary's scope is now much broader.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the introduction. I went with "provides a similar suite of functions" rather than "includes much the same functionality".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidchambers yeah that's better.
test('"sequence" method', function() { | ||
eq(S.Left('abc').sequence.length, 1); | ||
eq(S.Left('abc').sequence(S.Maybe.of), S.Just(S.Left('abc'))); | ||
test('"fantasy-land/reduce" method', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened to sequence
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #257 for the discussion which led to its removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed that one.
'1) null :: Null\n' + | ||
'\n' + | ||
'The value at position 1 is not a member of ‘Function’.\n'); | ||
test('"fantasy-land/extend" method', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about filter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also discussed in #257.
'1) null :: Null\n' + | ||
'\n' + | ||
'The value at position 1 is not a member of ‘List a’.\n'); | ||
eq(S.indexOf.toString(), 'indexOf :: a -> List a -> Maybe Integer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused as to what the criteria are for using Array over List in various type signatures. indexOf
seems to me to be more an array function than a list one given how expensive it is for the latter data structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the List type in Sanctuary is just a union of Array, String and other types with a length, excluding functions. The type signature has Array
when the function would not work on all of these other types as well; https://sanctuary.js.org/#list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The List type attempts to unify $.Array
and $.String
. It doesn't have anything to do with linked lists. It's a confusing type, certainly!
List
The List type constructor enables type signatures to describe ad hoc polymorphic functions which operate on either
Array
orString
values.Mental gymnastics are required to treat arrays and strings similarly.
[1, 2, 3]
is a list containing1
,2
, and3
.'abc'
is a list containing'a'
,'b'
, and'c'
. But what is the type of'a'
?String
, since JavaScript has no Char type! Thus:'abc' :: String, List String, List (List String), ...
Every member of
String
is also a member ofList String
! This affects the interpretation of type signatures. Consider the type ofindexOf
:a -> List a -> Maybe Integer
Assume the second argument is
'hello' :: List String
.a
must then be replaced withString
:String -> List String -> Maybe Integer
Since
List String
andString
are interchangeable, the former can be replaced with the latter:String -> String -> Maybe Integer
It's then apparent that the first argument needn't be a single-character string; the correspondence between arrays and strings does not hold.
As for S.indexOf
and S.lastIndexOf
, I'd really like to remove these functions. Addressing array elements by index is not a practice we should encourage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressing array elements by index is not a practice we should encourage
🏅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I vaguely remember the discussions we had about List
a few months ago now.
61c759e
to
1f2f964
Compare
1c4a09d
to
5b277bf
Compare
4c96b25
to
76aaed2
Compare
// negativeZero :: a -> Boolean | ||
var negativeZero = R.either(R.equals(-0), R.equals(new Number(-0))); | ||
// Thunk :: Type -> Type | ||
function Thunk(x) { return $.Function([x]); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@safareli, we can replace $.Function([x])
with $.Thunk(x)
once sanctuary-def supports this. :)
726a105
to
5d37f9b
Compare
5d37f9b
to
5c2ca39
Compare
This pull request:
S.__
;Original description: