Pewarta Proxy

📋 Server Request & Proxy Logs

Loading active proxy settings...
Developed by Khairul Adha (adhexa.id)
Mengambil log server...

⚙️ Pengaturan Proxy Target

Skip to content

Documenting how to construct algebraic datatypes from python #35

Open

Description

@mikesol

For interop, I'm having trouble calling a purescript function from python. If I have:

just :: Int -> Maybe Int
just = Just

addMaybe :: Maybe Int -> Maybe Int -> Maybe Int
addMaybe a b = (+) <$> a <*> b

Then this works:

import foo.Main.pure as Main
print(Main.addMaybe(Main.just(1))(Main.just(2)))

This produces the wrong output (it yields nothing):

import foo.Main.pure as Main
import foo.Data.Maybe.pure as Maybe
Just = Maybe.Just
print(Main.addMaybe({'value0': 3, '.t': Just})({'value0': 3, '.t': Just}))

and this crashes.

import foo.Main.pure as Main
import foo.Data.Maybe.pure as Maybe
Just = Maybe.Just
print(Main.addMaybe(Just(1))(Just(2)))

The first solution is of course fine, but it requires more boilerplate, and I'm assuming it must be possible to use the Just constructor or the Nothing constructor directly somehow.

Thanks!

Activity

  1. thautwarm commented on Aug 8, 2020

    @thautwarm
    Member

    for

    data C = Ctor Int Int

    to create Ctor:

    def new(t): return {'.t': t}
    Ctor(1, new(Ctor))
    Ctor.create(1)(2)

    Sorry for late reply!
    I'm now working for some technique meetup, will add documemtations after Aug 15

  2. thautwarm commented on Aug 8, 2020

    @thautwarm
    Member

    for enums, like Nothing,

    nothing = Nothing.value
  3. mikesol commented on Aug 10, 2020

    @mikesol
    Author

    Thanks!

    I tried this, but it looks like the problem still persists:

    -- snippet from Main.purs
    addM :: Maybe Int -> Maybe Int -> Maybe Int
    addM a b = (+) <$> a <*> b
    # testMain.py
    import pspy.Main.pure as Main
    import pspy.Data.Maybe.pure as Maybe
    
    print(Maybe.Just.create(1))
    print(Main.addM(Maybe.Just.create(1))(Maybe.Just.create(2)))

    yields

    {'value0': 1, '.t': <function ps_Just at 0x7f19302ea710>}
    {'.t': <function ps_Nothing at 0x7f1930349b90>}

    Thanks in advance for your help!

  4. thautwarm commented on Aug 10, 2020

    @thautwarm
    Member

    Sorry, purescripto 0.8.9 didn't release. Now pip install -U purescripto fixes all.

  5. thautwarm commented on Aug 10, 2020

    @thautwarm
    Member
    In [9]: import purescript_test.Main.pure as Main 
       ...: import purescript_test.Data.Maybe.pure as Maybe 
       ...:  
       ...: print(Maybe.Just.create(1)) 
       ...: print(Main.addM(Maybe.Just.create(1))(Maybe.Just.create(2)))                                                                   
    {'value0': 1, '.t': <function ps_Just at 0x7f8ec3bf0c10>}
    {'value0': 3, '.t': <function ps_Just at 0x7f8ec3bf0c10>}
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions