Skip to content

Documenting how to construct algebraic datatypes from python #35

@mikesol

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!

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